Setting environment variables globally in OSX

Setting Global Environment Variables in OSX

In *nix environments you use the .profile or .bash_profile (among others depending upon your shell) to set environment variables. In OSX these environment variables only apply to terminal sessions, not to bundled/GUI applications including those launched from spotlight. You may have properly set JAVA_HOME in your .profile file, and have them working from the command line, only to find them not effective when performing a task from your favorite IDE. For example when I run a maven install on one of my projects I get

Unable to find javadoc command: The environment variable JAVA_HOME is not correctly set

To remedy this, add something like this to the /etc/launchd.conf modified of course to the proper path.

# Set environment variables here so they are available globally to all apps
# (and Terminal), including those launched via Spotlight.
# After editing this file run the following command from the terminal to update 
# environment variables globally without needing to reboot.
# NOTE: You will still need to restart the relevant application (including 
# Terminal) to pick up the changes!
# grep -E "^setenv" /etc/launchd.conf | xargs -t -L 1 launchctl
# See
# and
# Note that you must hardcode the paths below, don't use enviroment variables.
# You also need to surround multiple values in quotes.
setenv JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home

You can use /usr/libexec/java_home from the command line to determine the proper path, but I could not get that to work embedded in the launchd.conf file like it does in your .bash_profile.


Contrary to what I've read, .bash_profile is processed even on non-login shells, at least in OSX.

I did not find ~/.MacOSS/environment.plist, nor ~/.launchd.conf nor ~/launchd.conf to be effective. At least not for a terminal session. I wasn't interested in a solution that did not work for both the terminal and applications so I stopped testing there.

Testing was done in Mountain Lion (v10.8.3 build 12D78) on Monday May 13, 2013.



This page was last modified on 13 May 2013, at 15:14.

Note: Content found in this wiki may not always reflect official Church information. See Terms of Use.