How to add /usr/local/bin in $PATH on Mac

MacosGitnode.jsPathProfile

Macos Problem Overview


When I do 'open .profile' in the terminal I have the following:

export PATH=$PATH:/usr/local/git/bin 

Now I installed node.js for Mac and it says,

> Make sure that /usr/local/bin is in your $PATH.

How can I add /usr/local/bin to export PATH=$PATH:/usr/local/git/bin?

Macos Solutions


Solution 1 - Macos

The PATH variable holds a list of directories separated by colons, so if you want to add more than one directory, just put a colon between them:

export PATH=$PATH:/usr/local/git/bin:/usr/local/bin

That syntax works in any Bourne-compatible shell (sh, ksh, bash, zsh...). But zsh, which is the default shell in recent versions of MacOS, also exposes the PATH another way - as a variable named (lowercase) $path, which is an array instead of a single string. So you can do this instead:

path+=(/usr/local/git/bin /usr/local/bin) 

In either case, you may want to check to make sure the directory isn't already in the PATH before adding it. Here's what that looks like using the generic syntax:

for dir in /usr/local/git/bin /usr/local/bin; do
   case "$PATH" in 
     $dir:*|*:$dir:*|*:$dir) :;; # already there, do nothing
     *) PATH=$PATH:$dir          # otherwise add it
   esac
done

And here's a zsh-specific version:

for dir in /usr/local/git/bin /usr/local/bin; do
  if (( ${path[(i)$dir]} > $#path )); then
    path+=($dir)
  fi
done

But in Zsh you can also just mark the array vars as accepting only unique entries:

typeset -TU PATH path

and even make your own pathlike variables mirrored in arrays:

typeset -TU PYTHONPATH pythonpath

Solution 2 - Macos

Try placing $PATH at the end.

export PATH=/usr/local/git/bin:/usr/local/bin:$PATH

Solution 3 - Macos

To make the edited value of path persists in the next sessions

cd ~/
touch .bash_profile
open .bash_profile

That will open the .bash_profile in editor, write inside the following after adding what you want to the path separating each value by column.

export PATH=$PATH:/usr/local/git/bin:/usr/local/bin:

Save, exit, restart your terminal and enjoy

Solution 4 - Macos

I've had the same problem with you.

cd to ../etc/ then use ls to make sure your "paths" file is in , vim paths, add "/usr/local/bin" at the end of the file.

Solution 5 - Macos

I tend to find this neat

sudo mkdir -p /etc/paths.d   # was optional in my case
echo /usr/local/git/bin  | sudo tee /etc/paths.d/mypath1

Solution 6 - Macos

In MAC OS Catalina, this are the steps that worked for me, all the above solutions did help but didn't solve my problem.

  1. check node --version, still the old one in use.
  2. cd ~/
  3. atom .bash_profile
  4. Remove the $PATH pointing to old node version, in my case it was /usr/local/bin/node/@node8
  5. Add & save this to $PATH instead "export PATH=$PATH:/usr/local/git/bin:/usr/local/bin"
  6. Close all applications using node (terminal, simulator, browser expo etc)
  7. restart terminal and check node --version

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionshinView Question on Stackoverflow
Solution 1 - MacosMark ReedView Answer on Stackoverflow
Solution 2 - MacossushilView Answer on Stackoverflow
Solution 3 - MacosDaniel RaoufView Answer on Stackoverflow
Solution 4 - MacosGuangYu YangView Answer on Stackoverflow
Solution 5 - Macosamerican-ninja-warriorView Answer on Stackoverflow
Solution 6 - MacosNadZView Answer on Stackoverflow