简体   繁体   English

如何在优胜美地OSX中设置环境变量?

[英]How to set environment variables in Yosemite OSX?

I tried setting up environment variables as explained in: https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/EnvironmentVars.html 我尝试按照以下说明中的说明设置环境变量: https : //developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/EnvironmentVars.html

But it didn't help. 但这没有帮助。 Writing .bash_profile is a workaround for executing an application via command line but IDEs like IntelliJ, Eclipse are not working with this setup. 编写.bash_profile是通过命令行执行应用程序的一种解决方法,但是IntelliJ,Eclipse之类的IDE不适用于此设置。

Is there an another work around for setting up environment variable in Yosemite? 在优胜美地设置环境变量还有另一种解决方法吗?

Create file named .profile in home directory - by opening a Terminal and using command “touch .profile” and Close Terminal. 在主目录中创建名为.profile的文件-通过打开终端并使用命令“ touch .profile”并关闭终端。 Open Terminal again. 再次打开终端。 Open that file in a plain-text editor (nano / vim in a Terminal window (current directory as home directory)). 在纯文本编辑器中打开该文件(在Terminal窗口中,使用nano / vim(当前目录作为主目录))。 Insert lines as “export VARIABLE_NAME=VARIABLE_VALUE” . 将行插入为“ export VARIABLE_NAME = VARIABLE_VALUE”。 Save, exit editor and close Terminal. 保存,退出编辑器并关闭终端。 Open Terminal and issue the command env to see all environment variables. 打开终端并发出命令env以查看所有环境变量。 Check the ones you exported. 检查导出的内容。 But environment variables defined in .profile are not passed to GUI applications. 但是.profile中定义的环境变量不会传递到GUI应用程序。 A workaround For GUI Applications . GUI应用程序的解决方法。 Use command “open -a Appname” in a Terminal session to start the GUI App. 在终端会话中使用命令“ open -a Appname”启动GUI App。

Another simple approach which works for all applications invoked from particular user : This approach works in 10.10.4 (atleast which i can verify not sure in other versions) create /Users/your_user/Library/LaunchAgents/custom.startup.plist with content 另一种适用于从特定用户调用的所有应用程序的简单方法:此方法在10.10.4中起作用(至少在其他版本中无法确定),使用内容创建/Users/your_user/Library/LaunchAgents/custom.startup.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 VARIABLE_NAME1 VARIABLE_VALUE1 | launchctl setenv VARIABLE_NAME2 VARIABLE_VALUE2 | launchctl setenv VARIABLE_NAME3 VARIABLE_VALUE3</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
</dict>
</plist>

logout and login again 注销并再次登录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM