muttsnutts notes

a dumping ground for things i will forget

Manage $PATH on Mac OS X Lion 10.7

Starting with Leopard, the program /usr/libexec/path_helper was introduced to help manage the $PATH environment variable.

It is started by the /etc/profile file:

if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`

When path_helper is called, it searches various files, looking for new paths to add…

  • it first reads from the file /etc/paths
  • then reads files under the folder /etc/paths.d/
  • and finally, oddly enough, the initial value of $PATH (prior to calling path_helper) is appended

Under the hood:

  • path_helper only appends unique paths, so duplicates are avoided
  • files from etc/paths.d are read in alphabetical order by filename
  • the default value for $PATH (prior to calling path_helper) is /usr/bin:/bin:/usr/sbin:/sbin
  • the default contents of file etc/paths is

How do I add more Paths ?

To add custom paths, you should create a plaintext file containing new paths (one per line) and place the file under the folder /etc/paths.d. Remember to end file with a newline!

Or from the terminal you can:

sudo sh -c 'echo "/some/other/path" >> /etc/paths.d/another_paths_file'

How do I make Homebrew happy ?

brew doctor commonly complains that /usr/bin is in your PATH before Homebrew's bin.
To fix this, move /usr/local/bin to the top of list in /etc/paths.

NOTE: The above changes are system-wide and will affect all users. If you only want to modify $PATH for a specific user, edit ~/.bash_profile, ~/.bash_login, or ~/.profile instead.