Where are system environment variables set in Mountain Lion?

I know this is an old question but I thought I would point out that in Yosemite /etc/launchd.conf no longer works (as confirmed by the man page). So here is an alternative.

Launch AppleScript Editor, enter a command like this:

do shell script "launchctl setenv variablename value"

(add as many lines as you like)

Now save (⌘S) as File format: Application. Finally open System SettingsUsers & GroupsLogin Items and add your new application.


I asked this question on the Apple Developer Forums as well and got back this, official response.

Change the Info.plist of the .app itself to contain an "LSEnvironment" dictionary with the environment variables you want.
~/.MacOSX/environment.plist is no longer supported.


As you have discovered, the use of environment.plist file is no longer followed, the variables stored in Info.plist as LSEnvironment strings are only set by launchd.

You cannot depend on them to set a general environment variable that the terminal will set if you call your program from the terminal/shell directly. The good news is the open -a command does trigger launchd to do the launching, so the variables will be set consistently for the app environment if not for the local shell environment.


Setting environment variables in /etc/launchd.conf is the way to go: Every application launched after a reboot by local shells, Finder or Spotlight inherits these variables - I have tested this extensively with Mountain Lion 10.8.3.

2 caveats:

  • Shells might overwrite the settings in their login scripts. (See For correct functioning in shells though...)
  • Launched apps might not expose the environment to their children. (ssh seems to behave like this - see ...why do remote shells via ssh do NOT inherit the environment...)

Try launchctl setenv NAME VALUE. I don't know if/what it does differently from editing launchd.conf, but it works for me in both Terminal and GUI apps. More details.

Note this doesn't survive across a reboot. Here's a way to fix that.