Wednesday, 18 May 2011

Modifying the UNIX environment in MacOS X

I wanted to tweak PATH and a few other environment variables after installing some software on my Macbook Air which runs MacOS X 10.6 Snow Leopard.  Here's what I discovered:

The environment is set up by /etc/profile.  This does 2 things: first it calls /usr/libexec/path_helper to set up PATH; then it calls /etc/bashrc to set up other environment variables for the shell.

The path_helper script works by first reading /etc/paths to get the default path elements (the file contains one directory path per line) and then by reading the files in /etc/paths.d (which are in the same format).

In the end I went for something simpler and put all my settings in $HOME/.bash_profile.  You should use this in preference to $HOME/.bashrc for setting your default environment because the latter file is run every time a shell starts, making things like export PATH="$HOME/bin:$PATH" have an undesired effect.