I wanted to have /usr/local/bin
to be listed before /usr/bin
in my PATH
environment variable.
One way to achieve this would be to add a ~/.profile
file with a line like this:
export PATH=/usr/local/bin:$PATH
This would result in /usr/local/bin
being listed twice. It wouldn’t hurt but it’s not pretty either.
If you look at /etc/profile
, you will see that the initial value of PATH
is set by path_helper(8)
.
The right way to change the order of default paths is to edit /etc/paths
. It contains one path per line, in descending order. Mine looks like this:
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
Pingback: Quirks of using PostgreSQL on Lion via Homebrew | Jeremy Tennant
Very helpful…thanks!
Thanks!
I needed this when setting up github on my mac (OS X Mountain Lion). They suggest using the ‘osxkeychain credential helper’ for password caching, but this is available only on git 1.7.10 or newer. Sadly, XCode ships with an older version of git.
I updated git via homebrew and used your instructions to let it take precedence over old ‘XCode Git’
All is well in my little world of git again 🙂
This was super helpful! thanks!
Thanks
Thanks, you are a life saver .
I successfully changed the /etc/paths file to make my path the order I would like. However when I echo $PATH, the order is not changed. I also noticed that in the /etc/profile file, it never calls path_helper(8).
After this failed I tried the hack that you said not to do, this also did not work. (I am trying to put /usr/local/bin before /usr/bin)
Stan, stupid question just to be sure, did you open a new terminal or restart your system? Or maybe you are using a different version of Mac OS X?
I am also having the same problem as Stan. Can’t get the order to change. Editing /etc/paths didn’t work (after restarting system). Neither did adding the change to ~/.profile or ~/.bash_profile
Any ideas? (OS X 10.8.3)
Thanks for this post. I am having a little bit of trouble applying to my situation because my $PATH variable looks very different from what is in the etc/profile.
My $PATH = /Users/joshuakatz/.rvm/gems/ruby-1.9.3-p429@global/bin:/Users/joshuakatz/.rvm/rubies/ruby-1.9.3-p429/bin:/Users/joshuakatz/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin
Here are the contents of “etc/path”
# System-wide .profile for sh(1)
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
if [ “${BASH-no}” != “no” ]; then
[ -r /etc/bashrc ] && . /etc/bashrc
fi
For whatever reason my /etc/paths file is Locked. I can Get Info on it, unlock it, even add permissions so that everyone should be able to read/write… but it still won’t actually unlock and let me edit it.
Any ideas?
In case it helps anyone, I figured out why the change wasn’t being applied to the PATH as mentioned in my previous comment:
If you are using ZSH, you will also need to modify the PATH string in ~/.zshrc
No commands (ls, open, touch etc) work in my terminal. But if i try /bin/ls it works. so i am guessing something is up with my $PATH. Please help. The following are the entries in my .bash_profile:
# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
#PATH=”/Library/Frameworks/Python.framework/Versions/3.3/bin:${PATH}”
#PATH=”$HOME/.rbenv/bin:$PATH”
PATH=”/usr/bin:{PATH}”
export PATH
PATH=”/usr/local/bin:{PATH}”
export PATH
PYTHONPATH=”${PYTHONPATH}:/Library/Frameworks/Python.framework/Versions/3.3/”
export PYTHONPATH
PYTHON_ROOT=”${PYTHON_ROOT}:/Library/Frameworks/Python.framework/Versions/3.3/”
export PYTHON_ROOT
# Setting PATH for Python 3.3
# The orginal version is saved in .bash_profile.pysave
PATH=”/Library/Frameworks/Python.framework/Versions/3.3/bin:${PATH}”
export PATH
# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH=”/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}”
export PATH
Pingback: João Paulo Pesce | Dynamic Library Path and Sudo in Mac OS X
Very helpful, exactly what I was looking for but couldn’t find anywhere else!
Pingback: tst – Ottoni
why would you want to put /usr/local/bin before /usr/bin ?