2

I read Mortimer's answer here https://stackoverflow.com/questions/25385934/setting-environment-variables-via-launchd-conf-no-longer-works-in-os-x-yosemite and added this file in /Users/MyName/Library/LaunchAgents called environment.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 GRADLE_HOME /Applications/gradle-2.0 
    launchctl setenv JAVA_HOME    
/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home
    </string>

  </array>
  <key>RunAtLoad</key>
  <true/>
</dict>
</plist>

Restarted my laptop, opened a terminal, and ran echo $GRADLE_HOME but it is still blank. How do I set an env var that is persistent throughout terminal sessions in Mac OS 10.10?

4
  • I don't understand plists very well, nor launchd, and I have avoided the Yosemite 'upgrade', but the payload of ProgramArgumentslooks funny to me: if the multiline string is passed as an argument to "sh", how is sh to know that there are two launchtctls to be executed? Dec 19, 2014 at 7:41
  • perhaps I didn't restart like I thought; I shut down and powered on, now it works.
    – MarcusH
    Dec 19, 2014 at 7:42
  • What happens if you delete the line launchctl setenv GRADLE_HOME /Applications/gradle-2.0 (so meaning there is only one command passed to sh)? Dec 19, 2014 at 7:42
  • Post that as an answer: it might be useful to someone who has not done that properly as you did. Dec 19, 2014 at 7:43

1 Answer 1

1

shut down and start the computer again. open the terminal and type echo $ENV_VAR and you should see the value you defined.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .