Reputation: 575
On my macOS Catalina 10.15.5, I have two git installed, one is system default version in folder /usr/bin
, one is install by brew in folder /usr/local/bin
. The system $PATH env variable in as following, it is obvious /usr/local/bin
is listed in front of /usr/bin
. However, when I issue git
on command line, the git in /usr/bin
was executed, rather than the other one. How could this happen? The shell is bash.
lannis20mbp:~ lannis$ echo $PATH
/Users/lannis/anaconda3/bin:/Users/lannis/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Visual Studio Code.app/Contents/Resources/app/bin
lannis20mbp:~ lannis$ which git
/usr/local/bin/git
lannis20mbp:~ lannis$ whereis git
/usr/bin/git
lannis20mbp:~ lannis$ git --version
git version 2.21.1 (Apple Git-122.3)
lannis20mbp:~ lannis$ /usr/bin/git --version
git version 2.21.1 (Apple Git-122.3)
lannis20mbp:~ lannis$ /usr/local/bin/git --version
git version 2.27.0
Upvotes: 0
Views: 218
Reputation: 208013
If you have added new binaries (executable programs) to your PATH since your shell started, you may need to rehash the lookup tables in your shell. You can do that with:
hash -r
If you want to know how the shell will interpret a given command, it is generally more useful to use type COMMAND
rather than which COMMAND
because type
will also tell you if the command is aliased:
type git
Here is a simple example. First, see that type find
and which find
give the same result:
which find
/usr/bin/find
type find
find is /usr/bin/find
Next, create an alias for find
which masks /usr/bin/find
:
alias find='ls'
Now, see that which
doesn't tell you what you want to know:
which find
/usr/bin/find
Whereas type
does:
type find
find is aliased to `ls'
Read more about the hash
, type
and other builtins with:
help hash
help type
Notes: hash, rehash, type, builtin, builtins, built-in, built-ins, PATH, which.
Upvotes: 1