Mac OS X Lion no longer recognizes environment.plist?

断了今生、忘了曾经 提交于 2019-11-27 01:46:42

问题


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?

Here's the contents of the 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>

回答1:


Use ~/.launchd.conf instead (see man launchctl).

See this answer for details.




回答2:


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.




回答3:


Whether or not Apple officially supports this mechanism, the current tech note Technical Q&A QA1067 is 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':

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

defaults write defaults write $HOME/.MacOSX/environment Root "1"



回答4:


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.

Creating the environment.plist file did the the trick.

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>



回答5:


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.




回答6:


I just got burned by something similar in Snow Leopard, and then figured out what the problem was.

I was doing:

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

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.




回答7:


By default, Mac OS X (10.7.4 and up) does not support it any more. See http://support.apple.com/kb/TS4267




回答8:


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

GPU_DUMP_DEVICE_KERNEL is 3

GPU_DUMP_TRK_ENVPLIST is (null)

GPU_DUMP_TRK_APPPLIST is (null)

GPU_DUMP_TRK_DOTPROFILE is (null)

GPU_DUMP_TRK_RUNSCRIPT is (null)

GPU_DUMP_TRK_SCHARGS is 1

GPU_DUMP_TRK_PUTENV is 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 did see a second tracer envar in Terminal, so something's probably gone wonky since then; long day....)




回答9:


You can edit your ~/.MacOSX/environment.plist with this example of $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

or edit this file:

/etc/paths

to change the order of system variables.




回答10:


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.

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.

Fortunately, one of those paths, /Applications/Xcode.app/Contents/Developer/usr/local/bin was never used.

Here was my solution. I created a symbolic link from the above directory to $HOME/bin.

Navigate to /Applications/Xcode.app/Contents/Developer/usr/local and execute sudo ln -s $HOME/bin bin.

My tools were now available to the Xcode platform.



来源:https://stackoverflow.com/questions/6770411/mac-os-x-lion-no-longer-recognizes-environment-plist

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!