Mac OS X 10.9 - 设置永久环境变量 [英] Mac OS X 10.9 - setting permanent environment variables
问题描述
如何在 Mac OS X 10.9 中设置永久环境变量(即每次启动新终端会话时不需要导出的环境变量)?我找到了许多关于修改我的 .bash_profile
和 .profile
的答案,但是这些选项似乎都不能作为永久性解决方案 - 只是暂时的.我要设置的变量是 MULE_HOME
.我的 bash 个人资料中有以下行:
How do I set a permanent environment variable (i.e. one that does not need exporting every time I start a new Terminal session) in Mac OS X 10.9? I've found a number of answers about modifying my .bash_profile
and .profile
, however neither of these options seem to work as permanent solutions - only temporary. The variable I'm trying to set is MULE_HOME
. I have the following line in my bash profile:
export MULE_HOME=$(/opt/mule-standalone-3.4.0)
但是,当我启动终端时,我得到以下行(不确定这是否是正常行为?):
However, when I start Terminal I get the following line (not sure if this is normal behaviour?):
-bash: /opt/mule-standalone-3.4.0: is a directory
运行一个简单的 env
命令会返回以下内容:
And running a simple env
command returns the following:
TERM_PROGRAM=Apple_Terminal
SHELL=/bin/bash
TERM=xterm-256color
TMPDIR=/var/folders/fc/68bqp4jj411gynj5qvwhq6z1shs1fy/T/
Apple_PubSub_Socket_Render=/tmp/launch-xKtkql/Render
TERM_PROGRAM_VERSION=326
TERM_SESSION_ID=E97BFE4B-AF85-4933-B252-0883CC085349
USER=dan
SSH_AUTH_SOCK=/tmp/launch-rEmTWW/Listeners
__CF_USER_TEXT_ENCODING=0x730C85DE:0:0
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
__CHECKFIX1436934=1
PWD=/Users/dan
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home
LANG=en_GB.UTF-8
MULE_HOME=
SHLVL=1
HOME=/Users/dan
LOGNAME=danwiseman
_=/usr/bin/env
为了解决这个问题,我目前必须在每次启动新的终端会话时输入 export MULE_HOME=/opt/mule-standalone-3.4.0
,虽然这并不费力,有点不方便.我在这里做错了什么导致变量仅被临时设置?提前致谢.
In order to get around this I'm currently having to type export MULE_HOME=/opt/mule-standalone-3.4.0
every time I start a new Terminal session which, whilst not strenuous, is a little inconvenient. What am I doing wrong here that is causing the variable to only be set temporarily? Thanks in advance.
推荐答案
删除 $(...)
位,这将尝试执行括号内的命令并设置 $MULE_HOME
到它产生的任何东西.在您的情况下, /opt/mule-standalone-3.4.0
不是可执行文件,因此您遇到了错误.
Drop the $(...)
bit, which would attempt to execute the command within the brackets and set $MULE_HOME
to whatever it produces. In your case /opt/mule-standalone-3.4.0
is not an executable, hence the error you are getting.
export MULE_HOME=/opt/mule-standalone-3.4.0
并使用 ~/.bashrc
而不是 ~/.bash_profile
.
and use ~/.bashrc
not ~/.bash_profile
.
似乎认为您应该在 ~/.bash_profile
脚本中设置环境变量,而不是 ~/.bashrc
脚本.
It seems opinion is that you should set environment variables in your ~/.bash_profile
script, and not ~/.bashrc
script.
这篇关于Mac OS X 10.9 - 设置永久环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!