Note
This no longer works with more recent versions of OS X, including 10.10 Yosemite (I'm not sure about 10.9 Mavericks). It does work with 10.8 Mountain Lion, however.
It's actually not too hard, but you do need to have admin privileges (using the sudo
command to write to /etc
).
From Terminal (or your favorite substitute), see if there's anything in the file /etc/launchd.conf
:
cat /etc/launchd.conf
If you get an error like
cat: /etc/launchd.conf: No such file or directory
then continue with the next step. If the cat
command does display some content, copy it.
Determine your system's current path, as we'll need to make sure we include it later:
launchctl getenv PATH
In your favorite editor, create a new text file with the following content, modified to fit your needs:
setenv PATH /usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/Users/YourUserName/bin:/path/to/gems/bin
Make sure you've included the entire contents of the path from the previous step, otherwise you'll break your system.
If the cat
command from Step 1 displayed some content, paste it into the new file before the setenv PATH
command. If it already contains a setenv PATH
command, just modify it to add the extra directories you need.
Save the new file in your home directory (/Users/YourUserName
) as launchd.conf
.
Go back to Terminal and enter:
sudo mv ~/launchd.conf /etc
to use admin power to move the new file to /etc
, replacing anything that was there before. Depending on your previous usage of the sudo
command, you may get a short "be careful doing what you're doing" message, but either way you'll need to enter your password. /etc
is not directly accessible through the Save dialog of graphical editors unless you're a real power user and know how to get around OSX's file system restrictions.
Reboot your computer
And you should be all set. If you're interested, launchd
and launchctl
use the csh
/tcsh
syntax, so you can't use the bash
/zsh
export PATH=/usr/local/bin:...
format.