Environment variables set in launchd will be available to all programs on the system. However since $HOME/.launchd.conf is not supported, this approach is used for global environment variables only.

Note: /etc/launchd.conf is not supported in Mac OS X 10.10 and higher; however launchctl is still there and will work as described here. Try instead with HowTo: Set an Environment Variable in Mac OS X - launchd.plist

The /etc/launchd.conf file contains a list of commands to be run by launchctl during startup. However environment variables set in /etc/launchd.conf cannot have spaces and cannot reference other environment variables; launchctl when run in Terminal does not suffer these limitations. Do note that /etc/launchd.conf does not exist by default, so we will need to create it.

A reboot is necessary to load the contents of /etc/launchd.conf. However if you were to run the corresponding launchctl commands in Terminal, you can alleviate the need for the reboot. Just remember that if you only do the launchctl commands, and do not put the entries in /etc/launchd.conf, it will not persist after reboot.

If you want to have a system wide environment variable that uses spaces or be dependent upon another environment variable, you can put the launchctl commands into one of the files Terminal reads. You will have to quit and relaunch Terminal to access the newly set variables.

Example entry in /etc/launchd.conf:


setenv JAVA_HOME /Library/Java/Home

Example corresponding launchctl command:

Terminal - hostname:~ user$

launchctl setenv JAVA_HOME /Library/Java/Home


Parts of this series