当有人说“编辑你的。plist文件”或“你的。profile”或“。Bash_profile”等等,这让我很困惑。我不知道这些文件在哪里,如果我必须这样做,如何创建它们,等等,以及为什么似乎有这么多不同的(为什么?)他们做不同的事情吗?)
所以,谁能非常耐心地向以前的Windows用户(迫切地想要更加熟悉最初有点困惑的OS X世界)解释如何一步一步地做到这一点?
我需要为GUI应用程序和命令行应用程序设置变量,目前是为需要变量的ant脚本设置变量,但很可能还有其他需求。
请注意,我也有Lion,因为你在谷歌上得到的许多答案似乎已经过时了…
还要注意,我几乎没有使用终端的经验。我愿意学习,但请为一个新手解释一下……
不幸的是,这些答案都没有解决我遇到的具体问题。
这里有一个简单的解决方案,不需要干扰bash。在我的例子中,它是让gradle工作(Android Studio)。
顺便说一句,这些步骤涉及OSX (Mountain Lion 10.8.5)
打开终端。
执行如下命令:
Sudo nano /etc/paths(或Sudo vim /etc/paths for vim)
转到文件底部,输入要添加的路径。
按control-x退出。
输入“Y”保存修改后的缓冲区。
打开一个新的终端窗口,然后输入:
回声路径美元
您应该看到新路径被追加到path的末尾
我从这篇文章中得到了这些细节:
http://architectryan.com/2012/10/02/add-to-the-path-on-mac-os-x-mountain-lion/#.UkED3rxPp3Q
我希望这能帮助到其他人
我选择了白痴路线。
将这些添加到/etc/profile的末尾
for environment in `find /etc/environments.d -type f`
do
. $environment
done
创建文件夹/etc/environments
在其中创建一个名为“oracle”或“whatever”的文件,并添加我需要全局设置的东西。
/etc$ cat /etc/environments.d/Oracle
export PATH=$PATH:/Library/Oracle/instantclient_11_2
export DYLD_LIBRARY_PATH=/Library/Oracle/instantclient_11_2
export SQLPATH=/Library/Oracle/instantclient_11_2
export PATH=$PATH:/Library/Oracle/instantclient_11_2
export TNS_ADMIN=/Library/Oracle/instantclient_11_2/network/admin
更多细节,这可能会对某人有所帮助:
Due to my own explorations, I now know how to set environment variables in 7 of 8 different ways. I was trying to get an envar through to an application I'm developing under Xcode. I set "tracer" envars using these different methods to tell me which ones get it into the scope of my application. From the below, you can see that editing the "scheme" in Xcode to add arguments works, as does "putenv". What didn't set it in that scope: ~/.MACOS/environment.plist, app-specific plist, .profile, and adding a build phase to run a custom script (I found another way in Xcode [at least] to set one but forgot what I called the tracer and can't find it now; maybe it's on another machine....)
GPU_DUMP_DEVICE_KERNEL为3
GPU_DUMP_TRK_ENVPLIST是(null)
GPU_DUMP_TRK_APPPLIST是(null)
GPU_DUMP_TRK_DOTPROFILE是(null)
GPU_DUMP_TRK_RUNSCRIPT是(null)
GPU_DUMP_TRK_SCHARGS为1
GPU_DUMP_TRK_PUTENV为1
... 另一方面,如果我进入终端并说“设置”,它似乎唯一得到的是一个来自.profile(我本以为它会捡到环境。plist也是,而且我确信我曾经在终端中看到第二个跟踪程序envar,所以从那以后可能有什么东西不稳定了。漫长的一天……)
Your .profile or .bash_profile are simply files that are present in your "home" folder. If you open a Finder window and click your account name in the Favorites pane, you won't see them. If you open a Terminal window and type ls to list files you still won't see them. However, you can find them by using ls -a in the terminal. Or if you open your favorite text editor (say TextEdit since it comes with OS X) and do File->Open and then press Command+Shift+. and click on your account name (home folder) you will see them as well. If you do not see them, then you can create one in your favorite text editor.
现在,添加环境变量相对简单,在概念上与窗口非常相似。在你的.profile中,每行添加一个变量名和它的值,如下所示:
export JAVA_HOME=/Library/Java/Home
export JRE_HOME=/Library/Java/Home
etc.
如果你正在修改你的"PATH"变量,请确保包含系统已经为你设置的默认PATH:
export PATH=$PATH:/path/to/my/stuff
现在是奇怪的部分,您可以打开一个新的终端窗口以使新变量生效,或者您需要键入.profile或.bash_profile来重新加载文件,并将内容应用到当前终端的环境中。
您可以在终端中使用“set”命令检查更改是否生效。只需输入set(如果您喜欢分页列表,可以再设置|),并确保您添加到文件中的内容。
至于在GUI应用程序中添加环境变量,这通常是不必要的,我想听到更多关于你正在具体尝试做什么,以便更好地给你一个答案。