100
votes

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?

6
I have voted to re-open this quesiton. It is about Node.js as well as Git (which is a tool that programmers use).KatieK
Yeah. If not here, where.bobobobo
Minor bit of information: I don't know about earlier versions of OS X, but as of Yosemite at least, /usr/local/bin is included in $PATH by default. You can check what's in your $PATH by running echo $PATH.Ross Henderson
MacOS generates PATH (partly) from /etc/paths, which is where you'll find /usr/local/bin listed, as well as /usr/bin, /bin, /usr/sbin, and /sbin. See Also (see apple.stackexchange.com/questions/79306TextGeek
echo $PATH will print your path. If you see /usr/local/bin between some colons, then it's in your path. source: stackoverflow.com/a/19202049/1459653Mark Gavagan

6 Answers

117
votes

This works in either bash (which is the default shell pre-Catalina) or zsh (which is the default shell from Catalina onward):

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

In zsh you can also do this for the same result:

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

Try placing $PATH at the end.

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

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

4
votes

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.

1
votes

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
1
votes

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