Change order of PATH entries on Mac OS X

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:


17 thoughts on “Change order of PATH entries on Mac OS X

  1. Pingback: Quirks of using PostgreSQL on Lion via Homebrew | Jeremy Tennant

  2. 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 🙂

  3. 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)

  4. 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?

  5. 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)

  6. 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`

    if [ “${BASH-no}” != “no” ]; then
    [ -r /etc/bashrc ] && . /etc/bashrc

  7. 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?

  8. 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

  9. 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


    export PATH

    export PATH

    export PYTHONPATH

    export PYTHON_ROOT

    # Setting PATH for Python 3.3
    # The orginal version is saved in .bash_profile.pysave
    export PATH

    # Setting PATH for Python 2.7
    # The orginal version is saved in .bash_profile.pysave
    export PATH

  10. Pingback: João Paulo Pesce | Dynamic Library Path and Sudo in Mac OS X

  11. Pingback: tst – Ottoni