.profile或.bash_profile


14

我很困惑,在哪里设置环境变量?

在.profile或.bash_profile中?

我同时使用mac osx和ubuntu。

我在这里使用哪一个感到困惑。

Answers:


21

阅读http://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files

 When Bash is invoked as an interactive login shell, or as a 
 non-interactive shell with the --login option, it first reads 
 and executes commands from the file /etc/profile, if that file
 exists. After reading that file, it looks for ~/.bash_profile, 
 ~/.bash_login, and ~/.profile, in that order, and reads and executes
 commands from the first one that exists and is readable. The 
 --noprofile option may be used when the shell is started to inhibit
 this behavior.

其他外壳也加载~/.profile(zsh,tcsh)..因此,我会将环境内容放入~/.profile

mac osx相关更新(感谢@Matt B)

有关gui程序,请阅读http://developer.apple.com/library/mac/#qa/qa2001/qa1067.html~/.MacOSX/environment.plist仔细编辑。


1
另外,在启动窗口管理器之前会先读取〜/ .profile,因此,您希望窗口管理器或其启动的应用程序要查看的环境变量应放在〜/ .profile中。
garyjohn

@garyjohn:Ubuntu或Mac OS是这种情况吗?
zneak 2010年

@zneak:我对Ubuntu相当有把握,对Mac OS X则不太肯定,但目前我无法访问任何一个进行验证。
garyjohn

1
@zneak:@garyjohn的说明不适用于Mac OSX。要更改GUI程序的环境变量,必须将设置放入~/.MacOSX/environment.plist。在此处查看更多信息:astro.washington.edu/users/rowen/AquaEnvVar.html
Matt B.

4

如果您使用bash,请在中~/.bash_profile。如果您使用其他外壳,请在~/.profile

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.