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.
Have you looked inside these two directories:
/etc/paths.d/
/etc/manpaths.d
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 that path_helper
is executed first. The man page for path_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:
$ cat /etc/paths
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
And, I believe, those account for the half of what you are seeing as set in PATH.
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.
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)
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.
Just put in .bashrc or .login and you'll be fine
来源:https://stackoverflow.com/questions/347286/what-are-the-various-files-that-could-have-path-declarations-for-os-x-terminal-i