布鲁诺是正确的。我已经进行了广泛的研究,如果您想设置所有GUI应用程序中都可用的变量,则唯一的选择是
/etc/launchd.conf。
打开终端提示
类型sudo vi /etc/launchd.conf(注意:此文件可能尚不存在)
将如下内容放入文件中
# Set environment variables here so they are available globally to all apps# (and Terminal), including those launched via Spotlight.## After editing this file run the following command from the terminal to update# environment variables globally without needing to reboot.# NOTE: You will still need to restart the relevant application (including# Terminal) to pick up the changes!# grep -E "^setenv" /etc/launchd.conf | xargs -t -L 1 launchctl## See http://www.digitaledgesw.com/node/31# and http://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x/## Note that you must hardpre the paths below, don't use environment variables.# You also need to surround multiple values in quotes, see MAVEN_OPTS example below.#setenv JAVA_VERSION 1.6setenv JAVA_HOME /System/Library/frameworks/JavaVM.framework/Versions/1.6/Homesetenv GROOVY_HOME /Applications/Dev/groovysetenv GRAILS_HOME /Applications/Dev/grailssetenv NEXUS_HOME /Applications/Dev/nexus/nexus-webappsetenv JRUBY_HOME /Applications/Dev/jrubysetenv ANT_HOME /Applications/Dev/apache-antsetenv ANT_OPTS -Xmx512Msetenv MAVEN_OPTS "-Xmx1024M -XX:MaxPermSize=512m"setenv M2_HOME /Applications/Dev/apache-mavensetenv JMETER_HOME /Applications/Dev/jakarta-jmeter
在vi中保存所做的更改,然后重新启动Mac。或使用上面的代码注释中显示的grep/xargs命令。
通过打开“终端”窗口并键入来证明您的变量正在工作,export并且您应该看到新的变量。这些也将在IntelliJ IDEA和您通过Spotlight启动的其他GUI应用程序中提供。



