OSX Persistent Environment Variables for GUI Applications

This worked for “macOS High Sierra” version: 10.13.6

  1. Create the file: my.startup.plist with the following contents:
<?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/Cellar/maven/3.6.0/libexec/bin:/usr/libexec/java_home/bin</string>
    <string>launchctl setenv M2_HOME /usr/local/Cellar/maven/3.6.0/libexec</string>
    <string>launchctl setenv M2 /usr/local/Cellar/maven/3.6.0/libexec/bin</string>
    <string>launchctl setenv JAVA_HOME /usr/libexec/java_home</string>
    <string>launchctl setenv POSTGRES_URL jdbc:postgresql://blah.blah.blah:5432/database</string>
    ..... etc .....
  </array>
  <key>RunAtLoad</key>
  <true/>
</dict>
</plist>

 

  1. Modify the environment variables with yours. Then save.
  2. Run the command: launchctl load ~/Library/LaunchAgents/my.startup.plist
  3. Restart your GUI applications that require the environment variables.

Leave a Reply

Your email address will not be published.