I am trying to get npm to work. In the process, I seem to have two versions of it installed: A corrupt one installed in ~/bin, and another I just compiled and ran make install to put it in /usr/local/bin/npm.

So, I moved the entire ~/bin folder into ~/old/bin ... but still when I run npm the system searches in ~/bin:

$ which npm
$ alias npm
-bash: alias: npm: not found
$ npm
-bash: /home/ubuntu/bin/npm: No such file or directory
$ echo $PATH

What causes Ubuntu to look for npm in ~/bin/npm ? I'm using Ubuntu 11.10. I don't know if the question is ubuntu-specific or not, it can be moved to askubuntu if needed.

I do see ~/bin in the PATH, but as far I as understand this only means that if npm was present at ~/bin then it would have used it ... but why does bash insist to look for it specifically there? Why doesn't it find /usr/local/bin/npm, even though the which command does find it?


The executable's previously known location is likely hashed by the shell. Resetting the shell's cache with hash -r should fix the issue.

If you don't want to reset the entire cache, you can delete the individual entry for npm using hash -d npm.

  • 1
    Excellent. Any reference to hash you can refer me to for further reading? Googling for linux hash does't seem to point me the right way. – ripper234 Mar 19 '12 at 11:24
  • 2
    @ripper234 - hash is a shell builtin command. The bash manpage holds more detail. – D_Bye Mar 19 '12 at 12:13
  • 5
    @ripper234 help hash also contains some good information. – Chris Down Mar 19 '12 at 12:45
  • Urk! I can't believe that in 2012 we are still using shells that require to be rehashed when the $PATH changes. I wonder if there is a bash option to require it to rehash at every command? – Norman Ramsey Mar 19 '12 at 17:56
  • @NormanRamsey - You could put hash -r in your $PROMPT_COMMAND I guess. – Chris Down Mar 19 '12 at 18:36

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.