Mac OSX Mountain Lion 的全局环境变量, For all GUI apps and Spotlight

以前osx的全局变量可以通过~/.MacOSX/envrironment.plist文件来设置,现在Mountain lion后就不行了。现在的文件换成/etc/launchd.conf 可以使用一下方法来设置:

1) Open a terminal prompt

2) Type sudo vi /etc/launchd.conf (note: this file might not yet exist)

3) Put contents like the following into the file


# 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 hardcode the paths below, don't use enviroment variables. 
# You also need to surround multiple values in quotes, see MAVEN_OPTS example below. 
#
setenv JAVA_VERSION 1.6 
setenv JAVA_HOME /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home 
setenv GROOVY_HOME /Applications/Dev/groovy 
setenv GRAILS_HOME /Applications/Dev/grails 
setenv NEXUS_HOME /Applications/Dev/nexus/nexus-webapp 
setenv JRUBY_HOME /Applications/Dev/jruby 
setenv ANT_HOME /Applications/Dev/apache-ant setenv ANT_OPTS -Xmx512M setenv MAVEN_OPTS "-Xmx1024M -XX:MaxPermSize=512m" 
setenv M2_HOME /Applications/Dev/apache-maven 
setenv JMETER_HOME /Applications/Dev/jakarta-jmeter

4) Save your changes in VI and reboot your Mac. Or use the grep/xargs command show in the code comment above.

如果不想手动修改文件,则可以使用

launchctl setenv PATH /opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin

来进行修改。

By Lu Jun

80后男,就职于软件行业。习于F*** GFW。人生48%时间陪同电子设备和互联网,美剧迷,高清视频狂热者,游戏菜鸟,长期谷粉,临时果粉,略知摄影。

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.