macos Mac OS X Lion 不再识别 environment.plist?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6770411/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mac OS X Lion no longer recognizes environment.plist?
提问by Michael Irwin
Just installed Lion today and my PATH env variable is no longer being set by ~/.MacOSX/environment.plist. Did something change? Can't seem to find any info on that or how to fix. Any ideas?
今天刚刚安装了 Lion,我的 PATH 环境变量不再由 ~/.MacOSX/environment.plist 设置。有什么改变吗?似乎无法找到任何关于此或如何修复的信息。有任何想法吗?
Here's the contents of the PLIST:
这是PLIST的内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PATH</key>
<string>/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11/bin:/Users/mdi/bin</string>
</dict>
</plist>
采纳答案by LaC
Use ~/.launchd.conf
instead (see man launchctl
).
使用~/.launchd.conf
替代(见man launchctl
)。
See this answerfor details.
有关详细信息,请参阅此答案。
回答by sworisbreathing
I ran into the same issue today. I called Apple Support and after being escalated to a Senior Advisor, then to her supervisor, I was told that they no longer support environment.plist and that there is no officially-supported method for defining environment variables in Mac OS 10.7.
我今天遇到了同样的问题。我打电话给 Apple 支持,在被升级为高级顾问,然后是她的主管后,我被告知他们不再支持 environment.plist 并且没有官方支持的方法来定义 Mac OS 10.7 中的环境变量。
回答by Shawn
Whether or not Apple officially supports this mechanism, the current tech note Technical Q&A QA1067is still accurate. An important caveat, however, is absent: the Property List needs to be in binary format. Xcode 4, when used to create new Property Lists, emits files that are in the text format (regardless of the type specified in File Inspector). So you either need to convert the saved file using 'plutil':
不管苹果官方是否支持这种机制,目前的技术说明Technical Q&A QA1067还是准确的。但是,缺少一个重要的警告:属性列表需要采用二进制格式。Xcode 4 在用于创建新的属性列表时,会发出文本格式的文件(无论文件检查器中指定的类型如何)。所以你要么需要使用'plutil'转换保存的文件:
plutil -convert binary1 environment.plist
or use 'defaults' to write out a new, template file that you can edit in Xcode (which will honor the original binary format when saving):
或使用“默认值”写出一个新的模板文件,您可以在 Xcode 中编辑该文件(保存时将遵循原始二进制格式):
defaults write defaults write $HOME/.MacOSX/environment Root "1"
回答by Programmer
Do it like brew and create a symlink in /usr/local/bin/. Works perfectly for me and is IMO a more unix-like solution where everything is a file.
像 brew 一样做并在 /usr/local/bin/ 中创建一个符号链接。非常适合我,并且 IMO 是一个更像 unix 的解决方案,其中一切都是一个文件。
回答by ostefano
Weird, cause here it works flawlessly. I had to setup a JRI environment to access R internals from a Java applications, and updating the .profile was not enough to have NetBeans catching all env vars.
奇怪,因为在这里它完美无缺。我必须设置 JRI 环境才能从 Java 应用程序访问 R 内部结构,更新 .profile 不足以让 NetBeans 捕获所有环境变量。
Creating the environment.plist file did the the trick.
创建 environment.plist 文件可以解决问题。
For reference this the file's content:
作为参考这个文件的内容:
Malessere:~ xxxxx$ cat .MacOSX/environment.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DYLD_LIBRARY_PATH</key>
<string>/Users/xxxxx/lib/jri-2.13</string>
<key>R_HOME</key>
<string>/Library/Frameworks/R.framework/Resources</string>
</dict>
</plist>
回答by Laird Nelson
I just got burned by something similar in Snow Leopard, and then figured out what the problem was.
我刚刚被雪豹中的类似东西烧伤了,然后找出了问题所在。
I wasdoing:
我在做:
$ cd
$ defaults write .MacOSX/environment FOO bar
...but it turns out that this is different from doing (in my case):
...但事实证明,这与做(在我的情况下)不同:
$ cd
$ defaults write /Users/ljnelson/.MacOSX/environment FOO bar
That is, the "path" (it's not really a path) to your domain must be the full file path to your $HOME/.MacOSX/environment.plist
file (minus the .plist
suffix). Anything else will write variables to a different domain (no idea where it got put), apparently.
也就是说,域的“路径”(它不是真正的路径)必须是文件的完整文件路径$HOME/.MacOSX/environment.plist
(减去.plist
后缀)。显然,其他任何东西都会将变量写入不同的域(不知道它放在哪里)。
So, upshot: always do defaults write /full/path/to/your/.MacOSX/environment VARNAME value
; don't use any shortcuts at all for the first argument to the write
subcommand.
所以,结果:总是做defaults write /full/path/to/your/.MacOSX/environment VARNAME value
;对于write
子命令的第一个参数,根本不要使用任何快捷方式。
回答by lazarus
I recently packaged up tools used by Xcode's Run Script Phase and placed them in $HOME/bin. My bash shell's PATH environment variable included this, so I assumed the Xcode would too.
我最近打包了 Xcode 的 Run Script Phase 使用的工具,并将它们放在 $HOME/bin 中。我的 bash shell 的 PATH 环境变量包括这个,所以我假设 Xcode 也会。
It never worked and I found issues like the one here.
它从未奏效,我发现了类似这里的问题。
I printed the PATH variable from the script (echo $PATH) called by Xcode to see what the PATH variable was set to.
我从 Xcode 调用的脚本 (echo $PATH) 中打印了 PATH 变量,以查看 PATH 变量的设置。
Fortunately, one of those paths, /Applications/Xcode.app/Contents/Developer/usr/local/bin was never used.
幸运的是,其中一个路径 /Applications/Xcode.app/Contents/Developer/usr/local/bin 从未被使用过。
Here was my solution. I created a symbolic link from the above directory to $HOME/bin.
这是我的解决方案。我创建了一个从上述目录到 $HOME/bin 的符号链接。
Navigate to /Applications/Xcode.app/Contents/Developer/usr/local and execute sudo ln -s $HOME/bin bin.
导航到 /Applications/Xcode.app/Contents/Developer/usr/local 并执行 sudo ln -s $HOME/bin bin。
My tools were now available to the Xcode platform.
我的工具现在可用于 Xcode 平台。
回答by mac joost
By default, Mac OS X (10.7.4 and up) does not support it any more. See http://support.apple.com/kb/TS4267
默认情况下,Mac OS X(10.7.4 及更高版本)不再支持它。请参阅http://support.apple.com/kb/TS4267
回答by Photovore
[[I'm copying this answer of mine into here, because it just may be helpful to someone:]]
[[我将我的这个答案复制到这里,因为它可能对某人有帮助:]]
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....)
由于我自己的探索,我现在知道如何以 8 种不同方式中的 7 种方式设置环境变量。我试图让 envar 通过我在 Xcode 下开发的应用程序。我使用这些不同的方法设置“跟踪器”环境变量,以告诉我哪些方法使其进入我的应用程序范围。从下面,您可以看到在 Xcode 中编辑“方案”以添加参数是有效的,“putenv”也是如此。没有在该范围内设置它的内容:~/.MACOS/environment.plist、特定于应用程序的 plist、.profile,并添加构建阶段以运行自定义脚本(我在 Xcode [至少] 中找到了另一种方法来设置一个但忘记了我称之为追踪器的东西,现在找不到了;也许它在另一台机器上......)
GPU_DUMP_DEVICE_KERNEL is 3
GPU_DUMP_DEVICE_KERNEL 为 3
GPU_DUMP_TRK_ENVPLIST is (null)
GPU_DUMP_TRK_ENVPLIST 为(空)
GPU_DUMP_TRK_APPPLIST is (null)
GPU_DUMP_TRK_APPPLIST 是(空)
GPU_DUMP_TRK_DOTPROFILE is (null)
GPU_DUMP_TRK_DOTPROFILE 为(空)
GPU_DUMP_TRK_RUNSCRIPT is (null)
GPU_DUMP_TRK_RUNSCRIPT 为(空)
GPU_DUMP_TRK_SCHARGS is 1
GPU_DUMP_TRK_SCHARGS 为 1
GPU_DUMP_TRK_PUTENV is 1
GPU_DUMP_TRK_PUTENV 为 1
... on the other hand, if I go into Terminal and say "set", it seems the only one it gets is the one from .profile (I would have thought it would pick up environment.plist also, and I'm sure that once I didsee a second tracer envar in Terminal, so something's probably gone wonky since then; long day....)
...另一方面,如果我进入终端并说“设置”,它似乎唯一得到的是来自 .profile 的那个(我原以为它也会选择 environment.plist,而我确定一旦我确实在终端中看到了第二个示踪剂 envar,所以从那以后可能有些事情变得不稳定了;漫长的一天......)
回答by gylow
You can edit your ~/.MacOSX/environment.plist
with this example of $PATH
:
您可以~/.MacOSX/environment.plist
使用以下示例编辑您的$PATH
:
defaults write $HOME/.MacOSX/environment PATH "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin:/opt/local/bin"
This will rewrite your ~/.MacOSX/environment.plist
这将改写你的 ~/.MacOSX/environment.plist
or edit this file:
或编辑此文件:
/etc/paths
to change the order of system variables.
改变系统变量的顺序。