Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 15 down vote accepted

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.

share|improve this answer
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
@ripper234 - hash is a shell builtin command. The bash manpage holds more detail. – D_Bye Mar 19 '12 at 12:13
@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 posting your answer, you agree to the privacy policy and terms of service.

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