如何设置 os x 中的应用程序使用的 $PATH
我使用 ant 构建我的项目,并使用“svnversion”可执行文件将版本 ID 插入到我的源代码中,以便于跟踪版本。
从命令行运行这个 ant 文件是有效的,我已经在 .profile 中设置了 $PATH 以包含 svnversion 的路径,并且它工作正常。
现在我尝试从 Eclipse 内部运行相同的 ant 文件,但这不起作用 - Eclipse 中的 PATH 的设置方式与 shell 的 PATH 不同,我怀疑这必须在某个 plist 中设置,但我不这样做不知道在哪里。
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.
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正确 - 它位于 plist 文件中。
该文件实际上包含您想要为整个登录会话设置的任何环境变量的键值对。 与 .profile/.cshrc 等不同,它可用于 GUI 程序。 不幸的是,您无法访问其他环境变量(例如,您无法使用 $HOME)或在此处使用任何其他编程结构。
更新:请注意,OS X 10.8 Mountain Lion 不再支持此功能,唉。
Correct -- it's in the plist file
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.
Update: note that this is no longer supported under OS X 10.8 Mountain Lion, alas.
在developer.apple.com上快速搜索发现为用户进程设置环境变量。
A quick search at developer.apple.com turned up Setting environment variables for user processes.
在 Mac OS X El Capitan (10.11.5) 上,这对我来说适用于每个用户的 PATH 条目(以及其他环境变量)。
$HOME/.profile
(如果使用 bash),让您的
.bash_profile
源该文件,然后.bashrc
。 这应该是您的.bash_profile
的全部内容:<代码># $HOME.bash_profile:
来源$HOME/.profile
源 $HOME/.bashrc
据我所知,Mac OS 在登录时不会为
PATH
获取.bash_profile
,大概是因为这通常运行速度非常慢(初始化 bash 完成等) )。 它看起来确实是$HOME/.profile
。您仍然需要
$HOME/.bash_profile
来触发 bash 读取$HOME/.bashrc
,否则对于交互式非登录终端将无法执行此操作,因为由Terminal.app
创建的。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).
$HOME/.profile
(if using bash), have your
.bash_profile
source that file, and.bashrc
. This should be the entire contents of your.bash_profile
:# $HOME.bash_profile:
source $HOME/.profile
source $HOME/.bashrc
Near as I can tell, Mac OS does not source
.bash_profile
on login forPATH
, presumably because that is often very slow to run (initializing bash completion etc). It does seem to read$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 byTerminal.app
.