Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the order of $PATH?

Tags:

bash

path

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?

like image 929
pill45 Avatar asked Aug 23 '15 19:08

pill45


People also ask

Does order matter in PATH variable?

I've seen numerous articles (see 1 2 3) addressing if order matters with regards to entries in the PATH environment variable and it is clear that the answer is a resounding yes.


1 Answers

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.

like image 145
Brad Peabody Avatar answered Sep 19 '22 09:09

Brad Peabody