Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

On Ask Different there are many questions regarding the PATH environment variable and how to set it for applications launched by a shell, by spotlight or via the finder (typical questions: How to set PATH for Finder-launched applications or How to change PATH environment variable...).

Answers range from sh startup scripts to /etc/paths to /etc/launchd.conf. Here I am after the answer for a unified setting of PATH for all apps under Mac OS X Mountain Lion 10.8.2.

share|improve this question

2 Answers 2

up vote 8 down vote accepted

After many trials with different options I conclude:

Is there a unified way to set the PATH for applications launched by different means (like shell script, Finder and Spotlight)? Well, yes and no:

  • No: Setting PATH in shell start up scripts (e.g. .bashrc) works only for apps launched by shells.
  • No: Setting PATH for the current launchd process via launchctl setenv PATH <...> does not work for me at all.
  • Yes: Setting PATH in /etc/launchd.conf (and restarting the system) will make the appropriate PATH visible in applications launched by Spotlight, Dock and Finder and subsequently (local) shells.
  • No: Remotely invoked shells do not inherit the environment. (See ...why do remote shells via ssh do NOT inherit the environment..)

Notes for set-up of shells:

  1. For correct functioning in local shells it is important to switch off the use of /usr/libexec/path_helper, because the default paths in /etc/paths might change the order of the paths in PATH.**

  2. To accommodate remote shells you need to re-import the launchd environment into the shell. Use something like this in your .bashrc:

# the vexatious path stuff
eval $(launchctl export)

Unfortunate consequences of the whole issue are:

  • No way to have these unified settings on a per user basis. (~/.launchd.conf does not work.)
  • No easy way to construct the PATH from different sources using techniques like home directory expansion et al.
share|improve this answer
    
Update: Setting PATH via /etc/launch.conf does not work for shells logged into remotely via ssh (I assume because the sshd does not pass its environment it inherits from its parent launchd to the child shell.). - I will edited the answer accordingly. –  halloleo Apr 14 '13 at 4:15
    
Answer updated with a solution for remote shells. –  halloleo Apr 18 '13 at 2:15
1  
Great answer; You can simplify sourcing of the launchd environment as follows: eval "$(launchctl export)". –  mklement May 31 '13 at 17:49
    
An easy way to edit /etc/launchd.conf is to just run sudo -e /etc/launchd.conf (if you are familiar with vi) or EDITOR=nano sudo -e /etc/launchd.conf (if you prefer a non-modal editor). –  patrix Aug 7 '13 at 7:01

Expanding on the previous answer, to change the path in /etc/launchd.conf, you'll need to do the following.

  1. Make sure you have Administrator privileges.

  2. 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
    
  3. Save it in your home directory as launchd.conf.

  4. Open Terminal.app (or your favorite substitute) and type:

    sudo mv ~/launchd.conf /etc

    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. All the command does is move the file to the /etc directory, which is not directly accessible when saving a file in TextEdit, for example. sudo (short for "Super User DO") is used because Administrator privileges are needed to write to that directory.

  5. Reboot your computer.

And you should be all set. Good luck!

share|improve this answer
    
Thanks for the details, but the question was not about ways how to modify launchd.conf, but rather about how all applications get the same PATH variable in a unified way. –  halloleo Aug 6 '13 at 11:36
    
Right, but I originally searched for the question trying to figure out how to set the PATH for my GUI apps, and I figured I'd help out whichever poor souls might not know how to effect the change... –  MattDMo Aug 6 '13 at 11:49
    
You have a valid point here; still, I think integrating your information in the answer is the better option. - I think this comment thread becomes a meta discussion, so I've opened it on meta.stackoverflow as What to do with an additional answer... –  halloleo Aug 6 '13 at 22:48
1  
actually, shouldn't this have been on meta.apple.stackexchange.com? –  MattDMo Aug 6 '13 at 23:01
    
Indeed, meta.apple.stackexchange.com would've been the correct place. I just didn't know that it exists... –  halloleo Aug 7 '13 at 2:09

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.