如何设置os x中应用程序使用的$ PATH

时间:2021-06-06 23:26:31

I'm using ant to build my project, and use the 'svnversion' executable to insert a version id into my sources for easy tracking of versions.

我正在使用ant来构建我的项目,并使用'svnversion'可执行文件将版本ID插入到我的源代码中以便于跟踪版本。

Running this ant file from the command line works, I've set my $PATH in .profile to include the path to svnversion and it works fine.

从命令行运行这个ant文件,我在.profile中设置$ PATH以包含svnversion的路径,它工作正常。

Now I try and run this same ant file from inside Eclipse and that does not work - the PATH in eclipse is set in another way than the PATH of the shell, I suspect this has to be set in a plist somewhere, but I don't know where.

现在我尝试从Eclipse内部运行这个相同的ant文件,但这不起作用 - eclipse中的PATH以不同于shell的PATH的方式设置,我怀疑这必须设置在某个地方的plist中,但我不知道知道在哪里。

3 个解决方案

#1


Correct -- it's in the plist file

正确 - 它在plist文件中

~/.MacOSX/environment.plist

This file actually contains key-value pairs for any environment variables you want to set, for the whole login session. Unlike .profile/.cshrc etc, it's available to GUI programs. Unfortunately, you can't access other environment variables (e.g., you can't use $HOME) or use any other programmatic constructs here.

对于整个登录会话,此文件实际上包含要设置的任何环境变量的键值对。与.profile / .cshrc等不同,它可用于GUI程序。遗憾的是,您无法访问其他环境变量(例如,您不能使用$ HOME)或在此处使用任何其他编程结构。

Update: note that this is no longer supported under OS X 10.8 Mountain Lion, alas.

更新:请注意,OS X 10.8 Mountain Lion不再支持此功能。

#2


A quick search at developer.apple.com turned up Setting environment variables for user processes.

在developer.apple.com上快速搜索出现了为用户进程设置环境变量。

#3


On Mac OS X El Capitan (10.11.5), this works for me for per-user PATH entries (and other environment variables, for that matter).

在Mac OS X El Capitan(10.11.5)中,这适用于每个用户的PATH条目(以及其他环境变量)。

  • create a file $HOME/.profile
  • 创建一个$ HOME / .profile文件

  • set all PATH related variables in that file
  • 设置该文件中的所有PATH相关变量

  • (if using bash), have your .bash_profile source that file, and .bashrc. This should be the entire contents of your .bash_profile:

    (如果使用bash),请将.bash_profile源文件和.bashrc。这应该是.bash_profile的全部内容:

    # $HOME.bash_profile: source $HOME/.profile source $HOME/.bashrc

    #$ HOME.bash_profile:source $ HOME / .profile source $ HOME / .bashrc

Near as I can tell, Mac OS does not source .bash_profile on login for PATH, presumably because that is often very slow to run (initializing bash completion etc). It does seem to read $HOME/.profile.

据我所知,Mac OS在登录PATH时不会提供.bash_profile,大概是因为这通常很慢(初始化bash完成等)。它看起来似乎是$ HOME / .profile。

You still need a $HOME/.bash_profile to trigger bash to read $HOME/.bashrc, which it otherwise wouldn't do for interactive, non-login terminals as the ones created by Terminal.app.

你仍然需要一个$ HOME / .bash_profile来触发bash来读取$ HOME / .bashrc,否则它不会像Terminal.app创建的那样为交互式非登录终端做。

#1


Correct -- it's in the plist file

正确 - 它在plist文件中

~/.MacOSX/environment.plist

This file actually contains key-value pairs for any environment variables you want to set, for the whole login session. Unlike .profile/.cshrc etc, it's available to GUI programs. Unfortunately, you can't access other environment variables (e.g., you can't use $HOME) or use any other programmatic constructs here.

对于整个登录会话,此文件实际上包含要设置的任何环境变量的键值对。与.profile / .cshrc等不同,它可用于GUI程序。遗憾的是,您无法访问其他环境变量(例如,您不能使用$ HOME)或在此处使用任何其他编程结构。

Update: note that this is no longer supported under OS X 10.8 Mountain Lion, alas.

更新:请注意,OS X 10.8 Mountain Lion不再支持此功能。

#2


A quick search at developer.apple.com turned up Setting environment variables for user processes.

在developer.apple.com上快速搜索出现了为用户进程设置环境变量。

#3


On Mac OS X El Capitan (10.11.5), this works for me for per-user PATH entries (and other environment variables, for that matter).

在Mac OS X El Capitan(10.11.5)中,这适用于每个用户的PATH条目(以及其他环境变量)。

  • create a file $HOME/.profile
  • 创建一个$ HOME / .profile文件

  • set all PATH related variables in that file
  • 设置该文件中的所有PATH相关变量

  • (if using bash), have your .bash_profile source that file, and .bashrc. This should be the entire contents of your .bash_profile:

    (如果使用bash),请将.bash_profile源文件和.bashrc。这应该是.bash_profile的全部内容:

    # $HOME.bash_profile: source $HOME/.profile source $HOME/.bashrc

    #$ HOME.bash_profile:source $ HOME / .profile source $ HOME / .bashrc

Near as I can tell, Mac OS does not source .bash_profile on login for PATH, presumably because that is often very slow to run (initializing bash completion etc). It does seem to read $HOME/.profile.

据我所知,Mac OS在登录PATH时不会提供.bash_profile,大概是因为这通常很慢(初始化bash完成等)。它看起来似乎是$ HOME / .profile。

You still need a $HOME/.bash_profile to trigger bash to read $HOME/.bashrc, which it otherwise wouldn't do for interactive, non-login terminals as the ones created by Terminal.app.

你仍然需要一个$ HOME / .bash_profile来触发bash来读取$ HOME / .bashrc,否则它不会像Terminal.app创建的那样为交互式非登录终端做。