Reputation: 8101
I installed GIT from the site on my mac, but git --version gave me the old installation (I guess xcode installation). So I solved doing this:
write:
export PATH=/usr/local/bin:$PATH
restart the terminal
Though, I think there's something in my configuration I could better setup.
My current echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin
So IT WORKS, but it's quite a mess, since I've got 2 /usr/local/bin AND an /usr/local/git/bin
Also, I cannot understand WHY now it works, since /usr/local/bin only contains bbedit commands:
I do not know very well all the path-config files and the real order they are read. I only know a few unix commands.. My current files in ~/ are:
~/.profile:
if [ -f ~/.bashrc ];
then
source ~/.bashrc
fi
~/bashrc:
. ~/bin/dotfiles/bashrc
then in . ~/bin/dotfiles/bashrc
. ~/bin/dotfiles/bash/env
. ~/bin/dotfiles/bash/config
. ~/bin/dotfiles/bash/aliases
and in . ~/bin/dotfiles/bash/env:
export PATH=/usr/local/bin:/opt/local/bin:/opt/local/sbin:$PATH
. ~/bin/dotfiles/bash/config is just empty
and . ~/bin/dotfiles/bash/aliases contains some alias commad.
Anyway, it SHOULD have read ~/bin/dotfiles/bash/env, but it doesn't. Or it reads it only after /etc/paths
~/.bash_profile is read first instead.
My current /etc/paths content:
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
Can anyone explain me the these mechanics? :P Or Maybe I should post this question to some Unix group?
Upvotes: 0
Views: 2674
Reputation: 729
See this for a comprehensive walkthrough of bash config files' loading order.
Upvotes: 0
Reputation: 522076
When you type any command on a *NIX shell, the shell tries to resolve that command using the $PATH
. Say your path is /usr/bin:/usr/local/bin
, then this happens:
$ foo
- Does /usr/bin/foo exist? No.
- Does /usr/local/bin/foo exist? No.
- Does foo exist in the current working directory?
In other words, it looks at each $PATH
element in turn and tries to find the executable you asked for there. This is the reason the typical configure
-make
-make install
procedure starts with a ./configure
, to make explicit that you want to run the configure
executable in the current directory, not some system-wide command.
To figure out which foo
it's actually choosing in the end, run:
$ which foo
You can run any command explicitly by providing its full path:
$ /usr/local/bin/foo # overrides /usr/bin/foo, should it exist
The export PATH=...:$PATH
directive in your initialization scripts is simply prepending certain paths to your path, allowing you to override the precedence in which order commands are resolved. It's not ideal that /usr/local/bin
is in there twice, but it's not really a problem either. You should take care not to let your path grow too long, since that may result in a lot of lookups for every command and may screw with your head, too.
Upvotes: 2