6

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.

John Topley
  • 113,588
  • 46
  • 195
  • 237
Tim Knight
  • 8,346
  • 4
  • 33
  • 32

5 Answers5

16

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
  • 10,406
  • 6
  • 33
  • 48
  • 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 Knight Dec 07 '08 at 05:55
  • @Tim K: The edit of my reply what I am to believe accounts for the other items. – ayaz Dec 07 '08 at 06:15
4

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
  • 4,073
  • 1
  • 24
  • 23
  • +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 Knight Dec 07 '08 at 05:58
  • have you tried "source .bashrc" as this command will exe that file – Lodle Dec 07 '08 at 06:17
1

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)

Matthew Schinckel
  • 35,041
  • 6
  • 86
  • 121
0

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 Knight
  • 8,346
  • 4
  • 33
  • 32
  • 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 Dec 07 '08 at 13:54
0

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

Kafka
  • 482
  • 3
  • 4