1. Clean up your OSX paths

    7 May 2010

    If you’re anything like me you’ve got a ton of paths in your .bash_profile. I defined them with some variables based upon applications then appended them onto $PATH at the bottom:


    Recently I discovered that OSX has a cool feature to help clean this up. It’s called path_helper

    Basically, it will read every file in /etc/paths.d and append each line of the file onto $PATH. For example, /etc/paths.d/mongo contains:


    /usr/local/mongodb/bin

    That’s it.

    Now my .bash_profile looks like:


    Any my /etc/paths.d looks like:


    You can confirm that it is properly creating the path list by running:

    /usr/libexec/path_helper -s

    This will show you the string it built. You’ll see that the first few paths are not ones that you defined in /etc/paths.d We’ll come back to that in a moment.

    Now, on the first line of my .bash_profile I was completely rewriting $PATH to change the lookup order for binaries. I prefer to compile everything myself and store it in /usr/local and I wanted the binaries in there to take precedence.

    This changes the lookup order because path_helper is getting those first few paths from /etc/paths. Just edit that file and put the files in whatever order you wish.

    Now restart your terminal session and you should be good to go!

    NOTE: These paths will be accessible to all accounts on your system.

Notes

  1. drj reblogged this from bcardarella
  2. bcardarella posted this