Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
/usr/local/bin/npm
$ alias npm
-bash: alias: npm: not found
$ npm
-bash: /home/ubuntu/bin/npm: No such file or directory
$ echo $PATH
/home/ubuntu/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
$

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
add comment

1 Answer

up vote 14 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
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
show 8 more comments

Your Answer

 
discard

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.