在 OS X 中修改环境变量(如 PATH)的正确方法是什么?
我在 Google 上搜索了一下,找到了三个不同的文件来编辑:
- /etc/路径
- ~/.profile
- ~/.tcshrc
我什至没有其中一些文件,而且我很确定 .tcshrc 是错误的,因为 OS X 现在使用 bash。这些变量,尤其是 PATH,在哪里定义?
我在跑 OS X v10.5 (豹)。
最佳答案
Bruno 正走在正轨上。我进行了广泛的研究,如果您想设置所有 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 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
通过打开终端窗口并键入
export
证明您的变量正在工作,您应该会看到新变量。这些也将在 IntelliJ IDEA 和您通过 Spotlight 启动的其他 GUI 应用程序中提供。
关于macos - 在 OS X 上设置环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/135688/