LoginSignup
2
0

More than 5 years have passed since last update.

To reflect env profile to GUI apps on macOS 〜OSX上のGUIアプリに環境変数を反映させる方法〜

Last updated at Posted at 2016-12-08

I had some trouble when I developed on IntelliJ IDEA.
Although I exported JAVA_HOME in .bashrc, it wasn't reflected to GUI app(IDEA).

R3 CordaはKotlinを使っています。ということでIntelliJ IDEAを使うことにしたのですが、
JAVA_HOMEの設定が反映されずにいて困っていました。

Please see the following steps.

ということで、以下のステップを御覧ください。

Step1. set JAVA_HOME in your .bash_profile

# Your other settings

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home

  • run: source ~/.bash_profile

Step2. make .osx-env-sync.sh

~/.osx-env-sync.sh
grep export $HOME/.bash_profile | while IFS=' =' read ignoreexport envvar ignorevalue; do
  launchctl setenv ${envvar} ${!envvar}
done

Step3. make osx-env-sync.plist

~/Library/LaunchAgents/osx-env-sync.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>osx-env-sync</string>
  <key>ProgramArguments</key>
  <array>
    <string>bash</string>
    <string>-l</string>
    <string>-c</string>
    <string>
      $HOME/.osx-env-sync.sh
    </string>
  </array>
  <key>RunAtLoad</key>
  <true/>
</dict>
</plist>

Step4. change mode the file to executable

chmod +x ~/.osx-env-sync.sh

Step5. make these preference valid

launchctl unload ~/Library/LaunchAgents/osx-env-sync.plist
launchctl load ~/Library/LaunchAgents/osx-env-sync.plist

Done! Please check if your GUI apps can read JAVA_HOME!!
I hope this article could be useful.

以上です。
GUIアプリに環境変数が反映されたことを確認出来たでしょうか?
少しでもお役に立てたら幸いです。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0