Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save christopher-baek/200c233c0c1ff4fbe9d3 to your computer and use it in GitHub Desktop.
Save christopher-baek/200c233c0c1ff4fbe9d3 to your computer and use it in GitHub Desktop.
Setting Environment Variables in OS X Yosemite

Setting Environment Variables in OS X Yosemite

shell

  • Terminal apps in OS X (Terminal, iTerm, etc.) process terminals as login shells, so these variables should be set in the ~/.bash_profile and not the ~/.bashrc file.

system (including GUI apps)

  • Create a ~/Library/LaunchAgents/environment.variables.plist file to have launchd run a script at login that will set environment variables
  • Create a /usr/local/bin/set-environment-variables.sh script (or wherever configured in the *.plist file) and "export" the environment variables here (bash syntax like "export JAVA_HOME ..." doesn't work here)
  • Register the *.plist file with launchd
launchctl load -w ~/Library/LaunchAgents/environment.variables.plist
  • Note the environment.variables.plist filename, the environment.variables label in the *.plist file match
# Add RVM to PATH for scripting
export PATH="${PATH}:${HOME}/.rvm/bin"
# Anaconda
export PATH=${HOME}/anaconda/bin:${PATH}
# Load RVM into a shell session *as a function*
[[ -s "${HOME}/.rvm/scripts/rvm" ]] && source "${HOME}/.rvm/scripts/rvm"
alias less="less -X"
set -o vi
<?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>environment.variables</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/set-environment-variables.sh</string>
</array>
<key>KeepAlive</key>
<false/>
<key>RunAtLoad</key>
<true/>
<key>WatchPaths</key>
<array>
<string>/usr/local/bin/set-environment-variables.sh</string>
</array>
</dict>
</plist>
#!/bin/bash
syslog -s -l warn "set-environment-variables.sh start"
launchctl setenv ANT_HOME /usr/local/opt/ant/libexec
launchctl setenv AXIS2_HOME /opt/apache-axis2/axis2-1.6.2
launchctl setenv CXF_HOME /opt/apache-cxf/apache-cxf-2.7.3
launchctl setenv JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home
launchctl setenv GROOVY_HOME /usr/local/opt/groovy/libexec
launchctl setenv GRAILS_HOME /usr/local/opt/grails/libexec
launchctl setenv GRADLE_HOME /usr/local/opt/gradle/libexec
launchctl setenv M2_HOME /usr/local/opt/maven/libexec
launchctl setenv MAVEN_HOME /usr/local/opt/maven/libexec
launchctl setenv ORACLE_HOME /opt/oracle-instant-client/instantclient_11_2
launchctl setenv TNS_ADMIN /opt/oracle-instant-client/instantclient_11_2/network/admin
syslog -s -l warn "set-environment-variables.sh complete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment