Questions

Forum Navigation
Please to create posts and topics.

Getting bash: /usr/local/bin/npm: No such file or directory on Linux

After several updates/upgrades for nodejs and npm, now I'm getting the /usr/local/bin/npm: No such file or directory error while I try using npm command. Already retried uninstalling/installing npm and nodejs but nothing seems to work.

How to fix this?

If npm is no longer installed in /usr/bin/npm, then chances are good bash(1) has hashed the executable name. The hashing saves repeated searches of all directories in your PATH every time you execute common programs. Since programs almost never change directories, this is usually a great idea.

To test, run hash -r. This will cause bash(1) to forget all its mappings. (This is harmless, it starts up with no mappings and grows them over time.) If this is the case, npm will execute the correct executable wherever it lives.

Usually, to properly uninstall npm and nodejs, on a Linux system, the following approach should work:

  • Go to /usr/local/lib and delete any node and node_modules.
  • Go to /usr/local/include and delete any node and node_modules directory.
  • If npm was installed with brew install node, then run brew uninstall node in your terminal.
  • Check your Home directory for any "local" or "lib" or "include" folders, and delete any "node" or "node_modules" from there.
  • Go to /usr/local/bin and delete any node executable.

You may need to do the additional instructions as well:

  • Remove: /usr/local/bin/npm
  • Remove: /usr/local/share/man/man1/node.1

Finally, use locate, which and whereis command to identify other additional locations in which npm/nodejs stuff has installed related binaries.