48

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?

8 Answers 8

59

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.

11
  • 2
    Yep; it just doesn't exist by default but creating it and setting proper entries helps
    – mgol
    Dec 18, 2013 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, 2014 at 18:44
  • 2
    @Tango Quit and reopen your terminal application after running launchctl setenv. launchctl setenv has never affected existing processes.
    – Lri
    Oct 25, 2014 at 12:50
  • 1
    This is so terrible, but is the correct answer! My god, Apple! Why must you be so "friendly" to laymen while kicking developers in the crotch whenever possible?
    – BuvinJ
    Jan 18, 2019 at 21:35
  • 2
    Could you update the answer for Catalina?
    – Raining
    Apr 16, 2020 at 11:24
12

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.

4
  • I've just posted a new question about whether there are ways to address the weakness described by @LauriRanta.
    – kuzzooroo
    Apr 7, 2014 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, 2014 at 2:14
  • This one is new for me. Nice! Oct 23, 2014 at 20:36
  • Could you update the answer for Catalina?
    – Raining
    Apr 16, 2020 at 11:27
3

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")

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

I found that launchctl 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 from /etc/launchd.conf work.

In order to fix it for shell scripts launched directly, I also set up PATH either in /etc/paths.d/* or in ~/.bashrc.

3
  • Where did you duplicate your ~/.bash_profile PATH to? To the shell script itself?
    – Mat Gessel
    Jan 30, 2021 at 7:18
  • 1
    I meant I copied PATHs from /etc/launchd.conf to ~/.bash_profile. Now, with Catalina, I migrated this setup to set up PATH either in /etc/paths.d/* or in ~/.bashrc, not in both. This works for all shell scripts. I also do launchctl setenv PATH ... on startup for GUIs. What I noticed is that it does not quite work for some GUIs. Jan 31, 2021 at 20:48
  • I've updated the answer. Jan 31, 2021 at 20:53
0

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.

2
  • 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, 2013 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, 2015 at 20:06
0

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
0

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>
1
  • 1
    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, 2015 at 17:00
-2

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

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .