In previous OS versions one could set the system-wide PATH environment variable in /etc/launchd.conf to make it available for all apps (not just the command line).

In Mavericks this appears to be no longer used.

Is there another technique for doing this in mavericks?

up vote 41 down vote accepted

Yosemite

/etc/launchd.conf is no longer supported in 10.10. See man launchctl:

The /etc/launchd.conf file is no longer consulted for subcommands to run during early boot time; this functionality was removed for security considerations.

You can now for example save this plist as ~/Library/LaunchAgents/my.startup.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>my.startup</string>
  <key>ProgramArguments</key>
  <array>
    <string>sh</string>
    <string>-c</string>
    <string>launchctl setenv PATH /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
</dict>
</plist>

The launchctl setenv command is ran as the user, so it only applies to processes launched in the user domain.

This method doesn't apply to applications that are reopened at login if "Reopen windows when logging back in" is checked.

Mavericks and earlier

In 10.9 and earlier, you can for example run

echo setenv PATH /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin|sudo tee -a /etc/launchd.conf

and then restart to apply the changes.

Other methods

/etc/paths and /etc/paths.d/ apply only (or mainly) to shells. The lines in /etc/paths and /etc/paths.d/* are added to the path by path_helper, which is run from /etc/profile, /etc/zshenv, and /etc/csh.login. I don't know any programs other than shells that would consider /etc/paths or /etc/paths.d/.

~/.MacOSX/environment.plist stopped working in 10.8.

  • 2
    Yep; it just doesn't exist by default but creating it and setting proper entries helps – mgol Dec 18 '13 at 0:19
  • On Yosemite, I found that some programs don't seem to see PYTHONPATH, which I have set in /etc/launchd.conf and I used your command line fix (the 2nd paragraph in your answer) and it doesn't seem to work, it just gives me the launchctl error/help message. – Tango Oct 18 '14 at 18:44
  • @Tango I edited the answer. /etc/launchd.conf was removed in 10.10. – user495470 Oct 23 '14 at 8:23
  • I'll add that my experience, while playing around with bash, is that, on 10.10, launchctl setenv seems to do nothing. I've tried setting env variables, then checked the value with echo and they were still undefined. – Tango Oct 25 '14 at 0:07
  • 1
    @Tango Quit and reopen your terminal application after running launchctl setenv. launchctl setenv has never affected existing processes. – user495470 Oct 25 '14 at 12:50

There is a much easier way. Place a text file in the folder /etc/paths.d/. In this text file, enter the desired path AND a newline. The best way is to create a new file for each path.

On my system, there is a file called MySQL with the text '/usr/local/mysql/bin' and a newline.

  • I've just posted a new question about whether there are ways to address the weakness described by @LauriRanta. – kuzzooroo Apr 7 '14 at 1:30
  • Just an anacdote: I have used this method as well, as it is the recommended "OS X way." I have not had much luck getting the System to honor consistently the PATH files I have in /etc/paths.d, and usually end up either using the export shell command, or placing my PATHs in ~/.bash_profile, which always work, if only for my current user account and not System-wide. If PATH files in /etc/paths.d always works for you, then I am jealous that your System is better behaved than mine ;) – chillin May 10 '14 at 2:14
  • This one is new for me. Nice! – CousinCocaine Oct 23 '14 at 20:36

You may be able to set environment variables in the file /etc/launchd-user.conf...

In Mavericks, I was able to configure an environment variable in the file using the line:

setenv TEST test

After a fresh boot, $TEST from /etc/launchd-user.conf is set.

Edit

It's possible that the syntax of the file at /etc/launchd.conf is invalid. Can you post the contents of that file for examination?

From what I'm seeing, setting the PATH variable in /etc/launchd.conf is working normally. However, launchd does not perform any parameter expansion. Therefore, if you have an entry like setenv PATH $PATH:/usr/local/bin, your resulting path would be set to "$PATH:/usr/local/bin" (note: not the value of PATH, but the text "$PATH")

  • Thanks, the problem I'm having is setting the PATH, other environment variables seem to work. – Tom Oct 23 '13 at 18:34
  • @Tom - I've provided an additional suggestion above – Eddie Kelley Oct 24 '13 at 5:25
  • 1
    is it really launch-user.conf or launch-[current_user_name].conf – Shanimal Jun 25 '14 at 0:38
  • /etc/launchd.conf containing 'setenv TEST test' does not propagate into Terminal on my Mavericks. – Dave X Mar 31 '15 at 20:22
  • Oops: s/Mavericks/Yosemite/. – Dave X Mar 31 '15 at 20:39

on my Mavericks install , adding "setenv PATH blablabla" to /etc/launchd.conf didn't work after reboot

so i added my new path to the end of /etc/paths , which worked.

  • It didn't work for me. I rebooted, /etc/paths contains everything I want and yet Sublime still sees only the original PATH. If I run it from terminal, it works. – mgol Dec 18 '13 at 0:05
  • The path_helper command in my /etc/profile uses /etc/paths and /etc/paths.d to overwrite any PATH that might have been set by /etc/launchd.conf – Dave X Mar 31 '15 at 20:06

I found that setenv PATH still works for me for Terminal and applications, but broke in shell scripts, launched directly via clicking or Open With in Terminal from, say, Finder. It's very strange. Other environment variables set in /etc/launchd.conf work.

In order to fix it for shell scripts launched directly, I duplicated PATH setting in ~/.bash_profile.

Editing /etc/paths.d or using .bash_profile didn't worked for me, however as suggested from someone else (I actually came here for upvote his answer, but I couldn't find it again?!), I edited /etc/paths which works for me

In my case, I added android-tool adb and android to terminal commands with pointing to their sdk paths (adb has moved to another directory nowadays) which look like

/usr/local/bin
...
/Applications/adt-bundle-mac/sdk/platform-tools  //new entries
/Applications/adt-bundle-mac/sdk/tools

SWEET, adding that XML to ~/Library/LaunchAgents/setenv.SVN.plist allowed BBEdit to use the subversion binaries I installed in /opt.

<clip>
<string>launchctl setenv PATH /opt/subversion/bin:$PATH</string>
<clip>
  • Any idea how to determine if this file supports parameter expansion? I may have set the path so the one in /opt is the only one. And I'm thinking that it's likely it does NOT support using $PATH. How would you determine the existing path to begin with? – Mark M May 22 '15 at 17:00

Simply add your 'bin' (the path that you want to add) path to /etc/paths file - reboot or relogin !!!

sudo vi /etc/paths 
(create a file (paths file) if it does't exist, I am using 'vi' editor, you can use your own as super user )
then, add your bin directory path like below 

/usr/local/mysql/bin
/usr/local/apache-ant-1.9.3/bin
/usr/local/gradle-1.11/bin

save the file and relogin ... hope this helps

protected by Community Jun 13 '16 at 5:22

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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