问题描述
当有人说编辑你的.plist文件或者你的.profile或者.bash_profile等时,这只是让我感到困惑。我不知道这些文件在哪里,如果我必须这样做,如何创建它们,以及为什么似乎有这么多不同的东西(为什么?他们做不同的事情?)
所以有人可以非常耐心地解释一个以前的Windows用户(如果最初有点混乱的OS X世界,想拼命地变得更加熟悉)如何做到这一步?
我需要将这些变量设置为GUI应用程序和命令行应用程序,目前它是一个需要变量的ant脚本,但很可能会有其他需要
请注意,我也有狮子会,因为你得到谷歌的许多答案似乎已经过时了狮子...
另请注意,我几乎没有使用终端的经验。我愿意学习,但请为新手解释...
首先,有一件事要认识OS X它是建立在Unix上的。这是.bash_profile所在的地方。当您在OS X中启动终端应用程序时,默认情况下您将获得一个bash shell。 bash shell来自Unix,加载时运行.bash_profile脚本。您可以修改此脚本以供用户更改设置。该文件位于:
〜/ .bash_profile
小牛更新
操作系统X小牛不使用environment.plist - 至少不适用于OS X Windows应用程序。您可以使用进行窗口应用程序。仍然支持.bash_profile,因为它是终端中使用的bash shell的一部分。
仅限狮子和山狮
OS X窗口应用程序从您的environment.plist文件接收环境变量。这可能是.plist文件的意思。该文件位于:
〜/ .MacOSX / environment.plist
/ pre>
如果您更改了environment.plist文件,那么OS X Windows应用程序,包括终端应用程序,将会设置这些环境变量。您的.bash_profile中设置的任何环境变量只会影响您的bash shell。
通常我只在.bash_profile文件中设置变量,不要更改.plist文件(或小牛的launchd文件)。大多数OS X窗口应用程序不需要任何自定义的环境。只有当一个应用程序实际上需要一个特定的环境变量,我改变了environment.plist(或在小牛的launchd文件)。
这听起来像你想要的是改变environment.plist文件,而不是.bash_profile。
最后一件事,如果你寻找这些文件,我想你不会找到它们。如果我回想起来,他们没有在我的初始安装Lion。
编辑以下是创建plist文件的一些说明。 / p>
- 打开Xcode
- 选择文件 - >新建 - >新建文件...
- 在Mac OS X下选择资源
- 选择一个plist文件
- 按照其他提示
要编辑文件,您可以按住Control键单击以获取菜单,然后选择添加行。然后,您可以添加一个键值对。对于环境变量,关键是环境变量名称,值是该环境变量的实际值。
创建plist文件后,可以使用Xcode打开它随时修改。
When someone says "edit your .plist file" or "your .profile" or ".bash_profile" etc, this just confuses me. I have no idea where these files are, how to create them if I have to do that, etc, and also why there seem to be so many different ones (why? Do they do different things?)
So could someone please explain very patiently to a previous Windows user (wanting desperately to become more familiar with the pleasant if initially somewhat confusing OS X world) how to do this step by step?
I need the variables to be set both for GUI applications and command line applications, and at the moment it's for an ant script that needs the variables, but there will most likely be other needs as well.
Please note that I have Lion too, since many of the answers you get Googling seem to be outdated for Lion...
Also note that I have practically zero experience using the Terminal. I'm willing to learn, but please explain for a novice...
解决方案First, one thing to recognize about OS X is that it is built on Unix. This is where the .bash_profile comes in. When you start the Terminal app in OS X you get a bash shell by default. The bash shell comes from Unix and when it loads it runs the .bash_profile script. You can modify this script for your user to change your settings. This file is located at:
~/.bash_profile
Update for Mavericks
OS X Mavericks does not use the environment.plist - at least not for OS X windows applications. You can use the launchd configuration for windowed applications. The .bash_profile is still supported since that is part of the bash shell used in Terminal.
Lion and Mountain Lion Only
OS X windowed applications receive environment variables from the your environment.plist file. This is likely what you mean by the ".plist" file. This file is located at:
~/.MacOSX/environment.plist
If you make a change to your environment.plist file then OS X windows applications, including the Terminal app, will have those environment variables set. Any environment variable you set in your .bash_profile will only affect your bash shells.
Generally I only set variables in my .bash_profile file and don't change the .plist file (or launchd file on Mavericks). Most OS X windowed applications don't need any custom environment. Only when an application actually needs a specific environment variable do I change the environment.plist (or launchd file on Mavericks).
It sounds like what you want is to change the environment.plist file, rather than the .bash_profile.
One last thing, if you look for those files, I think you will not find them. If I recall correctly, they were not on my initial install of Lion.
Edit: Here are some instructions for creating a plist file.
- Open Xcode
- Select File -> New -> New File...
- Under Mac OS X select Resources
- Choose a plist file
- Follow the rest of the prompts
To edit the file, you can Control-click to get a menu and select Add Row. You then can add a key value pair. For environment variables, the key is the environment variable name and the value is the actual value for that environment variable.
Once the plist file is created you can open it with Xcode to modify it anytime you wish.
这篇关于在Mac OS X Lion上设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!