Categories
Code

Paths in OSX 10.6 (Snow Leopard)

I’ve recently being doing a cleanup of my dotfiles (more on that later). In the process I commented out all of the “export PATH=...” statements in the profile and rc files in my home directory, but my path was still getting set to this:

/bin:/usr/bin:/sbin:/usr/sbin:usr/local/bin:/usr/local/git/bin:/usr/X11/bin

There are three problems with this:

  1. I’d prefer my /usr/local/bin to be first
  2. I don’t want/need either of those git/x11 paths
  3. I don’t like not understanding where things are getting set!

I eventually worked out that it came down to some files in my /etc directory :

#/etc/paths
/bin
/usr/bin
/sbin
/usr/sbin
/usr/local/bin
#/etc/paths.d/git
/usr/local/git/bin
#/etc/paths.d/x11
/usr/X11/bin

The paths.d method actually makes a lot of sense for a certain kind of application: it’s a nice clean way of adding bin files to the path nice and early (before any local modifications to the path).

Here’s the full order in which my paths were getting loaded in (I’m using zshell):

/etc/profile
/etc/profile.d/*
~/.zshrc (which loads in ~/.profile)

Apparently /etc/profile can come into play as well, but mine doesn’t set the path so I’m not sure what the ordering is. Indeed it looks like /etc can have it’s own set of shell-specific configs as well (mine seems to have a default bashrc), but that’s a whole other ballgame.

My solution

Now that I properly understand how my path is getting generated, I’m comfortable setting it from scratch in my local profile:

#~/.profile
export PATH=/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin

I prefer to have /usr/local/bin first, because this means that I can install things in /usr/local and symlink them into /usr/local/bin without conflicting with any old versions which came bundled with the operating system (and thus live in /usr/bin)

I could have achieved the same effect by editing /etc/paths, but I’d like to try and make my dotfiles as portable as possible

The following posts really helped me understand all this:

http://craiccomputing.blogspot.co.uk/2010/10/etcpathsd-as-way-to-configure-paths-in.html

http://superuser.com/questions/69130/where-does-path-get-set-in-os-x-10-6-snow-leopard

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.