This is an update for Mac OS X 10.7 Lion of the mac path article I wrote for $PATH settings on Mac Snow Leopard
Sidenote: /etc, /usr/, /tmp and more are actually symbolic links to /private/etc, /private/usr/, /private/tmp and so forth. In most cases this shouldn’t matter, when you navigate through a symbolic link, you’ll still end up in the real directory. Where it does matter is if you want to back up your “dot files” … you’ll need to make sure your backup utility is set to follow symlinks.
The order of precedence for parsing paths in Lion is as follows:
- /etc/paths.d/ filenames parsed alphabetically
- /etc/manpaths.d/ filenames parsed alphabetically
The Tao of Path Variables in Mac 10.7 Lion
- /etc/profile is the default startup script for Bash, which is what I’m using. (If you’re using a different shell, then you may have a different startup script). /etc/profile calls /usr/libexec/path_helper
- /etc/paths and /etc/manpaths contain the initial path environment variables. /etc/paths contains system-wide defaults:
/usr/bin /bin /usr/sbin /sbin /usr/local/bin
This is the file that you would edit if you need to parse /usr/local/bin before /usr/bin. (for example to make HomeBrew happy)
- path_helper looks for files in the directories: /etc/paths.d and /etc/manpaths.d and appends the paths found there to /etc/paths and /etc/manpaths respectively.On my system, /etc/paths.d and /etc/manpaths.d contain a file named 50-X11 which simply contains the paths for X11.Each file in these directories can have multiple paths, one path per line. Load order is alphabetical by filename, then follows the path order in the file.
- After /etc/profile has called path_helper, it then looks for ~/.bashrc
- Bash next looks for ~/.bash_profile. This is the file where you’ll set file and directory colors and could also be where you place your Path environment variables.
- Next, bash looks for ~/.bash_login. I don’t have this on my system so it’s ignored in my case
- next, bash looks for ~/.profile
Another file that can contain path variables is /etc/launchd.conf (which may not exist by default). This sets environment variables, including paths, for GUI applications (as opposed to the above files which are read by Bash in your Terminal). I’m not building graphical applications so don’t have much to say about it.
So, what that all means is that instead of exporting PATH environment variables to a .profile or .bash_profile in a user account directory, you (or your application) can make PATHs global by adding text files to the /etc/paths.d and /etc/manpaths.d directories.
If you need to control the order of a path, then try this:
In /etc/profile, add a line PATH=”" before the call to path_helper like this:
if [ -x /usr/libexec/path_helper ]; then PATH="" eval `/usr/libexec/path_helper -s` fi