I'm running Mountain Lion 10.8.4, and have my environment all customized through ~/.profile
so that when I run GUI apps like Sublime Text or Eclipse from the command line
open /Applications/Sublime\ Text\ 2.app
they inherit my $PATH
settings, allowing the app to run external commands not in OSX's very limited default path. However, I'd really like to be able to open programs through Finder or the Dock and give them the same path I use on the command line. launchctl setenv PATH $PATH
doesn't work in 10.8. How do I set this up?
Best Answer
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
:If you get an error like
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:
In your favorite editor, create a new text file with the following content, modified to fit your needs:
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 thesetenv PATH
command. If it already contains asetenv PATH
command, just modify it to add the extra directories you need.Save the new file in your home directory (
/Users/YourUserName
) aslaunchd.conf
.Go back to Terminal and enter:
to use admin power to move the new file to
/etc
, replacing anything that was there before. Depending on your previous usage of thesudo
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
andlaunchctl
use thecsh
/tcsh
syntax, so you can't use thebash
/zsh
export PATH=/usr/local/bin:...
format.