当有人说“编辑你的。plist文件”或“你的。profile”或“。Bash_profile”等等,这让我很困惑。我不知道这些文件在哪里,如果我必须这样做,如何创建它们,等等,以及为什么似乎有这么多不同的(为什么?)他们做不同的事情吗?)
所以,谁能非常耐心地向以前的Windows用户(迫切地想要更加熟悉最初有点困惑的OS X世界)解释如何一步一步地做到这一点?
我需要为GUI应用程序和命令行应用程序设置变量,目前是为需要变量的ant脚本设置变量,但很可能还有其他需求。
请注意,我也有Lion,因为你在谷歌上得到的许多答案似乎已经过时了…
还要注意,我几乎没有使用终端的经验。我愿意学习,但请为一个新手解释一下……
更多细节,这可能会对某人有所帮助:
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,所以从那以后可能有什么东西不稳定了。漫长的一天……)
更多细节,这可能会对某人有所帮助:
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,所以从那以后可能有什么东西不稳定了。漫长的一天……)
在Mac OS上设置PATH环境变量
打开终端程序(默认在应用程序/实用程序文件夹中)。
运行以下命令
touch ~/.bash_profile; open ~/.bash_profile
这将在默认文本编辑器中打开文件。
ANDROID SDK为例:
你需要添加路径到你的Android SDK平台工具和工具目录。在我的例子中,我将使用“/Development/android-sdk-macosx”作为SDK的安装目录。增加如下一行:
export PATH=${PATH}:/Development/android-sdk-macosx/platform-tools:/Development/android-sdk-macosx/tools
保存文件并退出文本编辑器。
执行.bash_profile来更新PATH。
source ~/.bash_profile
现在,每次你打开终端程序,你的PATH将包括Android SDK。