在OS X上设置环境变量 [英] Setting environment variables on OS X

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

问题描述

在OS X中修改环境变量(如PATH)的正确方法是什么?

What is the proper way to modify environment variables like PATH in OS X?

我在Google上浏览了一下,找到了三个要编辑的文件:

I've looked on Google a little bit and found three different files to edit:

  • /etc/paths
  • 〜/.profile
  • 〜/.tcshrc

我什至没有这些文件,而且我很确定 .tcshrc 是错误的,因为OS X现在使用bash.这些变量(尤其是PATH)在哪里定义?

I don't even have some of these files, and I'm pretty sure that .tcshrc is wrong, since OS X uses bash now. Where are these variables, especially PATH, defined?

我正在运行 OS X v10.5 (豹).

推荐答案

Bruno正步入正轨.我已经进行了广泛的研究,如果您想设置所有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 applications, your only option is /etc/launchd.conf.

请注意, environment.plist不会为通过Spotlight启动的应用程序工作.这是史蒂夫·塞克斯顿(Steve Sexton)在此处记录的.

Please note that environment.plist does not work for applications launched via Spotlight. This is documented by Steve Sexton here.

  1. 打开终端提示

  1. Open a terminal prompt

键入sudo vi /etc/launchd.conf(注意:此文件可能尚不存在)

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

将类似以下内容的内容放入文件

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 environment 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

  • 将更改保存在vi中,然后重新启动Mac.或使用 grep /

  • Save your changes in vi and reboot your Mac. Or use the grep/xargs command which is shown in the code comment above.

    通过打开终端"窗口并键入export来证明您的变量正在工作,您应该会看到新的变量.这些功能还将在您通过Spotlight启动的IntelliJ IDEA和其他GUI应用程序中提供.

    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 IDEA and other GUI applications you launch via Spotlight.

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

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