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 environment variables?
Open Terminal and issue the command env to see all environment variables. Check that the ones you defined have the value you assigned to them.
The shell uses environment variables to store information, such as the name of the current user, the name of the host computer, and the default paths to any commands.
app/Contents/Resources/app/bin/ in my case.
Create an environment.plist
file in ~/Library/LaunchAgents/
with this content:
<?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 PRODUCTS_PATH /Users/mortimer/Projects/my_products
launchctl setenv ANDROID_NDK_HOME /Applications/android-ndk
launchctl setenv PATH $PATH:/Applications/gradle/bin
</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
You can add many launchctl
commands inside the <string></string>
block.
The plist
will activate after system reboot. You can also use launchctl load ~/Library/LaunchAgents/environment.plist
to launch it immediately.
[Edit]
The same solution works in El Capitan too.
Xcode 7.0+ doesn't evaluate environment variables by default. The old behaviour can be enabled with this command:
defaults write com.apple.dt.Xcode UseSanitizedBuildSystemEnvironment -bool NO
[Edit]
There a couple of situations where this doesn't quite work. If the computer is restarted and "Reopen windows when logging back in" is selected, the reopened windows may not see the variables (Perhaps they are opened before the agent is run). Also, if you log in via ssh, the variables will not be set (so you'll need to set them in ~/.bash_profile). Finally, this doesn't seem to work for PATH on El Capitan and Sierra. That needs to be set via 'launchctl config user path ...' and in /etc/paths.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With