16

echo $PATH gives me

/Library/Frameworks/Python.framework/Versions/3.4/bin:/Applications/Sublime Text 2.app/Contents/SharedSupport/bin:/Users/pathreskoo/anaconda/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin

but when I want to change the order of /usr/local/bin to the front of /Library/Frameworks/Python.framework/Versions/3.4/bin, I type

sudo emacs /etc/paths

I only get

/usr/local/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:

How can I insert /usr/local/bin in front of my PATH?

nbro
  • 15,395
  • 32
  • 113
  • 196
pill45
  • 599
  • 3
  • 8
  • 23

2 Answers2

29

You can set your PATH in the file .bash_profile, which is in your home directory.

More specifically, you can simply add the following line to the end of that file

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

This results in /usr/local/bin being prepended to the existing PATH. In other words, the folder /usr/local/bin is inserted in front of your PATH, and so it would have the highest priority. You can also append a folder to your path by doing

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

In general, you can set the order of the folders or files that you export in a similar way as the following:

export PATH=/usr/local/bin:/Applications/Sublime Text 2.app/Contents/SharedSupport/bin:/Users/pathreskoo/anaconda/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin

Note: this is not the only place you can set the PATH, but it is a common one.

nbro
  • 15,395
  • 32
  • 113
  • 196
Brad Peabody
  • 10,917
  • 9
  • 44
  • 63
  • 3
    It's safer to just add `/usr/local/bin` to the front of the path, rather than completely override the inherited value (`PATH=/usr/local/bin:$PATH`). Duplicates don't cause any harm, and your path is unlikely to get so large as to cause performance issues. – chepner Aug 23 '15 at 19:58
0

Your $PATH normally overridden by the initiation part of your shell. Normally follows the system-wide profile (/etc/profile), then user-side profile (if you use bash .profile, .bash_profile, .bashrc) and any source command in these files. The overridden command mainly in .bashrc

Edit you .bashrc file and find $PATH, you may find the export command and delete the path you do not want. export $PATH=/usr/local/bin:$PATH override the command user-wide.

胡亦朗
  • 397
  • 1
  • 3
  • 9
  • would work better as a comment, as it doesn't stand by itself as an answer to the question... or perhaps it could use much editing! good luck. – cregox Aug 30 '22 at 21:02