哪些文件可能包含 OS X 终端的 PATH 声明?
所以我在 OS X Leopard 上遇到了路径问题。 看来 OS X 正在添加我没有说明的其他路径,并且它扰乱了我的路径优先级。 我只有一个 .bash_login
文件,没有 .bashrc
或 .profile 文件。 我的 .bash_login 文件是这样的:
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
当我运行导出时,这是它返回的路径:
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/opt/local/bin:/usr/local/git/bin"
关于可以将 /usr/bin 放在那里以及如何获取 /usr/ 的任何想法local/bin 具有更高的优先级。
我也将其标记为 Rails,因为这就是我现在正在做的事情...看来 Mac 内置 Ruby、Rails 和 Gems 的优先级高于我在 /usr/ 安装的版本local/bin
,我想也许你们这些 Rubyists 也能帮忙。
So I'm having a path issue on OS X Leopard. It seems OS X is adding other paths that I'm not stating and it's messing with my path priority. I only have a .bash_login
file, I don't have a .bashrc
or a .profile file. My .bash_login
file is as such:
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
When I run export this is the path it returns:
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/opt/local/bin:/usr/local/git/bin"
Any ideas on what could be putting /usr/bin in there and how I could get /usr/local/bin
to be a higher priority.
I'm tagging this for Rails too because that's what I'm working on right now... it seems the Mac built-in Ruby, Rails, and Gems are taking priority over the one I have installed at /usr/local/bin
, figured maybe you fellow Rubyists could help too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您查看过这两个目录吗:
这些目录中的文件中定义的任何路径都会自动附加到 PATH 变量中——我主要使用这两个目录将第三方安装的应用程序放入 PATH 中。 另外,请查看 OS X 上
path_helper
的手册页。编辑:查看
/etc/profile
的内容,我可以看到首先执行的是path_helper
。path_helper
的手册页指出,在读取/etc/paths.d/
和/etc/manpaths.d/
目录中的文件之前,path_helper
读取并设置文件/etc/paths
和/etc/manpaths
中定义的路径。 查看/etc/paths
可以发现这一点:而且,我相信,这些内容占了您在 PATH 中看到的设置的一半。
Have you looked inside these two directories:
Any paths defined in files in those directories get appended automatically to PATH variable -- I mostly use those two directories to put third-party installed applications in the PATH. Also, do have a look at the man page of
path_helper
on OS X.EDIT: Looking at the contents of
/etc/profile
, I can see thatpath_helper
is executed first. The man page forpath_helper
says that prior to reading files in/etc/paths.d/
and/etc/manpaths.d/
directories,path_helper
reads and sets up the paths defined in the files/etc/paths
and/etc/manpaths
. A look at/etc/paths
reveals this:And, I believe, those account for the half of what you are seeing as set in PATH.
您的更改似乎没有被应用。 注意 no /usr/local/mysql/bin
阅读 bash 联机帮助页中有关 INVOCATION 的部分,.bash_login 仅当它是登录 shell 时才会被读取 - 而终端 shell 则不是。 您需要将其放入 ~/.bashrc 中。 它将针对登录和非登录 shell 进行读取。
It looks like your changes aren't being applied. Note no /usr/local/mysql/bin
Read the bash manpage section on INVOCATION, .bash_login is only read if it is a login shell -- which the terminal shell is not. You need to put it into ~/.bashrc instead. It will be read for logins and non-login shells.
您还可以将内容放入 ~/.MacOSX/Environment.plist 中,详细信息请参见 https://web.archive.org/web/20150330034300/http://www.astro.washington.edu/users/rowen/AquaEnvVar.html
这将使环境变量可供所有应用程序使用,而不仅仅是那些通过终端 (bash) 会话启动的应用程序。
(看来现在也有更好的建议了)
You can also put stuff into ~/.MacOSX/Environment.plist, as detailed at https://web.archive.org/web/20150330034300/http://www.astro.washington.edu/users/rowen/AquaEnvVar.html
This will make the Environment Variables available to all applications, not just those started through a terminal (bash) session.
(It seems that there is a better suggestion there now, too)
我还在Apple的支持论坛上发现了一篇有趣的文章:
.bash_login不再执行
有了这些信息,我发现了一个被忽略的空白 .bash_profile 文件,该文件正在加载 - 并杀死了我试图在路径中设置的所有信息。
所以我想根据情况我们可以有几个“正确”的答案。
I've also come across an interesting article on Apple's support forums:
.bash_login no longer executed
With that information I found an overlooked blank .bash_profile file that I had that was loading - and killing all of the information I was trying to set in my path.
So I guess it looks like we could have several "correct" answers depending on the situation.
只需输入 .bashrc 或 .login 就可以了
Just put in .bashrc or .login and you'll be fine