views:

622

answers:

5

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.

+3  A: 

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.

Brian C. Lane
+1 don't have it working quite yet - but the man page gives me a start Brian thanks. I'm wondering if a complete logoff is necessary for the bashrc to load?
Tim K.
have you tried "source .bashrc" as this command will exe that file
Lodle
+7  A: 

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.

ayaz
Thanks ayaz, that at least told me how X11 and git paths were getting added on there. Still on the hunt for the other items.
Tim K.
@Tim K: The edit of my reply what I am to believe accounts for the other items.
ayaz
awesome! thank you so much!
Tim K.
You're welcome, Tim. :)
ayaz
A: 

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.

Tim K.
What I do is to toss all user-specific BASH initialisation stuff in ~/.bashrc, and place a line in ~/.bash_profile to source ~/.bashrc.
ayaz
A: 

Just put in .bashrc or .login and you'll be fine

Kafka
A: 

You can also put stuff into ~/.MacOSX/Environment.plist, as detailed at 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.

Matthew Schinckel