How to fix bash looking for a program in the wrong dir (Issues setting up NPM on Ubuntu 11.10)

9,051

Solution 1

Chances are that you did have a /usr/local/bin/npm and your shell remembers it in its cache. You can clear the cache with hash -d npm. The cache is not shared within shell instances, so the problem will not last.

The reason the output of which is inconsistent with what your shell does is that which is an external program, so it does not share bash's cache. Use type instead, it's a shell built-in so it's more reliable.

Solution 2

You can consider yourself rather lucky, because you've just learned the easy way, that you should not put your additional binary dirs in front of the PATH variable. A sane PATH variable in your case should look something like

PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/steven/local/bin:/home/steven/local/bin:/home/steven/local/bin:/home/steven/local/bin

But the problem that actually caused your error is not really with PATH, rather with what npm command has probably been aliased to. To learn that, type

type npm

Another option could be that /usr/local/bin/npm is just a broken symlink to /home/steven/local/bin/npm (but you'd learn that with the above command also).

Share:
9,051

Related videos on Youtube

Steven Lu
Author by

Steven Lu

Updated on September 18, 2022

Comments

  • Steven Lu
    Steven Lu almost 2 years

    This time I ran the "trusting" install script curl http://npmjs.org/install.sh | sudo sh from the dir /.

    $ which npm
    /usr/local/bin/npm
    $ npm
    bash: /home/steven/local/bin/npm: No such file or directory
    $ echo $PATH
    /home/steven/local/bin:/home/steven/local/bin:/home/steven/local/bin:/home/steven/local/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
    $ ls /home/steven/local/bin
    node  node-waf
    $ ls /usr/local/bin
    node  node-waf  npm  npm_g  npm-g
    

    It seems like some script somewhere is polluting my $PATH. What I wonder is, if bash can't find the program in the first dir it looks in, doesn't it keep looking through $PATH? It should be able to find it in /usr/local/bin!

    npm really, really doesn't seem to want to just work. I think I'm gonna go load up a slightly older Ubuntu and give this another go...

  • bnikhil
    bnikhil over 12 years
    "does not share bash's cache"