I've looked for an answer too and eventually found a related answer to this question, How to set system-wide environment variables on OS X Mavericks.
It is a security measure, particularly to ensure secure shell users with a disabled shell, where SHELL
is set to /bin/false
, cannot gain unsolicited access.
One workaround is settting PermitUserEnvironment
in your ssh config; please read security caveats in above mentioned answer before doing this.
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.
Best Answer
You can try something like this:
This will pass environment variable
VARIABLE
into the launched app and later it will be cleaned, but will remain in the app.