found drama

get oblique

a layman’s guide to $PATH on OS X

by Rob Friesel

Recently, while working my way through a strange issue with my shell’s $PATH,1 I had the chance to take a (semi) deep dive into how OS X constructs the $PATH. I’m jotting these notes down here in part for myself, and hopefully so someone else won’t have to do the same amount of… archaeology.

And now, how OS X constructs your $PATH:

  1. First order of business: when OS X kicks off bash, it kicks off /etc/profile.
  2. /etc/profile in turn fires /usr/libexec/path_helper -s which is going to parse the system’s critical default paths.
  3. /usr/libexec/path_helper first loads /etc/paths which is going to construct our initial $PATH from:
    • /usr/bin
    • /bin
    • /usr/sbin
    • /sbin
    • /usr/local/bin
  4. After /etc/paths, /usr/libexec/path_helper looks at each file in /etc/paths.d, which for me included X11 (adding /usr/X11/bin) and git (adding /usr/local/bin/git).
  5. Once it’s through all of that, then OS X is ready to look at what you want. I’m told that this can live in ~/.bash_profile, but I’ve got mine in ~/.profile. You can set your $PATH flat out, if you want–completely blow away what OS X has set up for you anyway–or you can embrace what it has given you (since you’ll want these anyway) and work with and around that default $PATH.

And/but wait… There’s more. There’s this odd-ball: ~/.MacOSX/environment.plist — which has a PATH property in the plist. As far as I can tell, environment.plist has no direct impact on what goes into your bash $PATH. I haven’t found anything definitive, but it appears that it sets the PATH for applications system-wide, but that bash is otherwise going to take care of itself (vide supra).2

UPDATE: (12/8/2012) There is yet another odd-ball that I missed the first time around: /etc/launchd.conf — and it is your only option for getting items onto the PATH for GUI apps. In other words, if you need something on your PATH from within your IDE, you better make sure that /etc/launchd.conf is adding it. (See also: this Stack Overflow thread and these Apple Developer Library docs; hat tip to Nick H. for finding this one.)

  1. Spoiler alert: it turned out to be a goofy copy/paste error of my own making. But hey… crisitunity! []
  2. It’s worth point out (in retrospect?) that Apple recommends against using the environment.plist approach. (Source.) []

About Rob Friesel

Software engineer by day, science fiction writer by night. Author of The PhantomJS Cookbook and a short story in Please Do Not Remove. View all posts by Rob Friesel →

Leave a Reply

Your email address will not be published. Required fields are marked *