I have an older version of Git installed at:


I recently downloaded a newer version to:


When I type:

which git

I get the location of the old version. I believe that this is just because /usr/bin/ appears before /usr/local/bin in my $PATH variable and so the older version of git is 'found' first.

To test this, I renamed the older version of git to "git_old". Now when I type:

which git

I get the location of the newer version, as expected. But when I type:

git --version

I get the following error:

-bash: /usr/bin/git: No such file or directory

I'm just wondering why my computer is going back to looking in the old location for Git?


Bash caches the full path to executables so that it doesn't have to look through $PATH every time.

You can see what is in the cache using the hash command:

deltik@node51 [~]$ hash
hits    command
   1    /usr/bin/git

This cache can be cleared with hash -r:

deltik@node51 [~]$ hash -r
deltik@node51 [~]$ hash
hash: hash table empty

Additional Resources

  • 2
    wtf I never knew this, awesome. Jul 25 '16 at 15:34
  • 1
    Most other shells do the same thing, but they don't all use hash -r to reload the cache. Singer, such as SSH, use rehash as the command instead.
    – Moshe Katz
    Jul 26 '16 at 4:18
  • PATH=$PATH should clear the cache. hash -r is not needed.
    – jrw32982
    Jul 27 '16 at 20:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.