1

I tried to use snap to install node. The package was stale. So, I snap remove'd that, and I installed node via apt from the nodesource PPA. Great:

$ node -v
v14.15.5

However, when I try to use npm, I get the following error:

$ npm
bash: /snap/bin/npm: No such file or directory

This is weird to me, since /usr/bin is on my $PATH and:

$ ls /usr/bin/npm
/usr/bin/npm

What has snap done to my system's normal method of looking for binaries in $PATH?

Also, how do I fix this?

3
  • Does the behavior change after running hash -d npm? Feb 18, 2021 at 23:29
  • 1
    @steeldriver yes. So, had my terminal had already previously looked up the location of npm, and had stored in somewhere for quick lookup?
    – Him
    Feb 18, 2021 at 23:33
  • Yes - see fo example What does hash -r command do? Feb 18, 2021 at 23:38

1 Answer 1

3

Your shell doesn't constantly search for binaries once it's found one-- to do so would be a waste of time in most cases. It caches the result. That bites hard if you end up removing a binary after it's already cached where it found it, though.

You can fix this by simply starting a new shell, or clearing the cache in an existing shell with hash -r.

2
  • "starting a new shell" — is that equivalent to "open a new terminal window"? So this looking for binaries / caching happens every time a new terminal window is opened?
    – Levente
    Mar 18, 2021 at 0:59
  • 1
    Opening a new window does start a new shell, but that's not the only way to do it (e.g. you might use screen, or byobu, or SSH...).
    – kyrofa
    Mar 19, 2021 at 1:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .