设置环境变量在OS X? [英] Setting environment variables in OS X?

查看:113
本文介绍了设置环境变量在OS X?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是修改像OSX PATH环境变量的正确方法?我看着谷歌上一点点,发现3种不同的文件进行编辑:

What is the proper way to modify environment variables like PATH in OSX? I've looked on Google a little bit and found 3 different files to edit:


  • 的/ etc /路径

  • 〜/ .profile文件

  • 〜/ .tcshrc文件

我甚至不具有一定的这些文件,我pretty确保 .tcshrc文件的是错误的,因为OSX现在使用的bash。任何人有其中这些变量,尤其是PATH,是指任何想法?

I don't even have some of these files, and I'm pretty sure that .tcshrc is wrong, since OSX uses bash now. Anybody have any idea where these variables, especially PATH, are defined?

编辑:我运行OS X 10.5

I'm running OS X 10.5

推荐答案

布鲁诺是正确的轨道上。我已经做了广泛的研究,如果你想要设置在所有GUI应用可用的变量,你唯一的选择就是 /etc/launchd.conf

Bruno is right on track. I've done extensive research and if you want to set variables that are available in all GUI apps, your only option is /etc/launchd.conf

请注意, environment.plist通过聚焦启动的应用程序无法正常工作。这是由史蒂夫·塞克斯顿这里记录。

1)打开一个终端提示

1) Open a terminal prompt

2)输入 sudo的VI /etc/launchd.conf (注意:此文件可能还不存在)

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

3)把内容像下面到文件

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)保存在您的VI的变化和重新启动您的Mac。或使用grep / xargs的命令显示在上面的code评论。

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

5)证明你的变量是通过打开一个终端窗口,输入导出工作,你应该看到您的新的变数。这些也将在的IntelliJ和其他GUI应用程序通过您启动聚光灯

5) Prove that your variables are working by opening a Terminal window and typing export and you should see your new variables. These will also be available in IntelliJ and other GUI apps you launch via Spotlight.

这篇关于设置环境变量在OS X?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆