It looks like the launchd.conf
does not load my environment variable anymore.
Has anyone else noticed that?
Is there another solution to permanently set
It is possible to set environment variables on Mac OS X 10.10 Yosemite with 3 files + 2 commands.
Main file with environment variables definition:
$ ls -la /etc/environment
-r-xr-xr-x 1 root wheel 369 Oct 21 04:42 /etc/environment
$ cat /etc/environment
#!/bin/sh
set -e
syslog -s -l warn "Set environment variables with /etc/environment $(whoami) - start"
launchctl setenv JAVA_HOME /usr/local/jdk1.7
launchctl setenv MAVEN_HOME /opt/local/share/java/maven3
if [ -x /usr/libexec/path_helper ]; then
export PATH=""
eval `/usr/libexec/path_helper -s`
launchctl setenv PATH $PATH
fi
osascript -e 'tell app "Dock" to quit'
syslog -s -l warn "Set environment variables with /etc/environment $(whoami) - complete"
Service definition to load environment variables for user applications (terminal, IDE, ...):
$ ls -la /Library/LaunchAgents/environment.user.plist
-rw------- 1 root wheel 504 Oct 21 04:37 /Library/LaunchAgents/environment.user.plist
$ sudo cat /Library/LaunchAgents/environment.user.plist
Label
environment.user
ProgramArguments
/etc/environment
KeepAlive
RunAtLoad
WatchPaths
/etc/environment
The same service definition for root user applications:
$ ls -la /Library/LaunchDaemons/environment.plist
-rw------- 1 root wheel 499 Oct 21 04:38 /Library/LaunchDaemons/environment.plist
$ sudo cat /Library/LaunchDaemons/environment.plist
Label
environment
ProgramArguments
/etc/environment
KeepAlive
RunAtLoad
WatchPaths
/etc/environment
And finally we should register these services:
$ launchctl load -w /Library/LaunchAgents/environment.user.plist
$ sudo launchctl load -w /Library/LaunchDaemons/environment.plist
What we get:
Issues / problems:
In order your env variables were correctly taken by applications after system reboot you will need:
This happens due to Apple denies explicit ordering of loaded services, so env variables are registered in parallel with processing of the "reopen queue".
But actually, I reboot my system only several times per year (on big updates), so it is not a big deal.