在 Mac OS X Lion 上设置环境变量 [英] Set environment variables on Mac OS X Lion

查看:41
本文介绍了在 Mac OS X Lion 上设置环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当有人说编辑您的 .plist 文件"或您的 .profile"或.bash_profile"等时,这让我感到困惑.我不知道这些文件在哪里,如果我必须这样做,如何创建它们等等,还有为什么似乎有这么多不同的文件(为什么?他们做不同的事情吗?)

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?)

那么有人可以非常耐心地向以前的 Windows 用户解释如何一步一步地做到这一点吗?(拼命地想要更加熟悉令人愉快但最初有点令人困惑的 OS X 世界)?

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?

我需要为 GUI 应用程序和命令行应用程序设置变量,目前它是为需要这些变量的 ant 脚本设置的,但很可能还有其他需要.

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.

请注意,我也有 Lion,因为您在谷歌上搜索的许多答案对于 Lion 来说似乎已经过时了...

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...

推荐答案

首先,要认识到 OS X 的一件事是它构建在 Unix 上.这是 .bash_profile 的用武之地.当您在 OS X 中启动终端应用程序时,默认情况下您会获得一个 bash shell.bash shell 来自 Unix,当它加载时,它运行 .bash_profile 脚本.您可以为您的用户修改此脚本以更改您的设置.该文件位于:

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

<小时>

小牛队更新

OS X Mavericks 不使用 environment.plist - 至少不用于 OS X Windows 应用程序.您可以将启动配置用于窗口化应用程序..bash_profile 仍然受支持,因为它是终端中使用的 bash shell 的一部分.

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.

仅限狮子和山狮

OS X 窗口化应用程序从您的 environment.plist 文件接收环境变量.这可能就是您所说的.plist"文件的意思.该文件位于:

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

<小时>

如果您对 environment.plist 文件进行更改,则 OS X Windows 应用程序(包括终端应用程序)将设置这些环境变量.您在 .bash_profile 中设置的任何环境变量只会影响您的 bash shell.


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.

通常我只在我的 .bash_profile 文件中设置变量并且不更改 .plist 文件(或小牛队上的 launchd 文件).大多数 OS X 窗口化应用程序不需要任何自定义环境.只有当应用程序确实需要特定的环境变量时,我才更改 environment.plist(或 Mavericks 上的启动文件).

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).

听起来您想要的是更改 environment.plist 文件,而不是 .bash_profile.

It sounds like what you want is to change the environment.plist file, rather than the .bash_profile.

最后一件事,如果您查找这些文件,我想您不会找到它们.如果我没记错的话,它们不在我最初安装的 Lion 中.

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.

以下是创建 plist 文件的一些说明.

Here are some instructions for creating a plist file.

  1. 打开 Xcode
  2. 选择文件 -> 新建 -> 新建文件...
  3. 在 Mac OS X 下选择资源
  4. 选择一个 plist 文件
  5. 按照其余提示操作

要编辑文件,您可以按住 Control 单击以获取菜单并选择添加行".然后您可以添加一个键值对.对于环境变量,键是环境变量名称,值是该环境变量的实际值.

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.

创建 plist 文件后,您可以随时使用 Xcode 打开它以进行修改.

Once the plist file is created you can open it with Xcode to modify it anytime you wish.

这篇关于在 Mac OS X Lion 上设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆