Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

It's actually not too hard, but you do need to have admin privileges (using the sudo command to write to /etc).

  1. 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.

  2. Determine your system's current path, as we'll need to make sure we include it later:

    launchctl getenv PATH
    
  3. 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.

  4. Save the new file in your home directory (/Users/YourUserName) as launchd.conf.

  5. 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.

  6. 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.