Vaibhav Mishra
Vaibhav Mishra

Reputation: 445

sudo: npm: command not found, while running npm with sudo

I installed nodejs v8.11.2 and npm v5.6.0 using the command nvm install 8.11.2.

When I opened my system after shutting it down for a while my system and wrote npm -v in the terminal, it said npm is not installed, and to install it with sudo apt install npm.

However when I again entered nvm install 8.11.2, it said that nodejs and npm are already installed and it began using it. Sometimes when opening a different terminal, npm -v says that npm is not installed. And later when I used the command sudo npm install, the output came:

sudo: npm: command not found

So I installed npm with sudo apt-get install npm, but it installed npm v3.5.2 and updating it with npm install npm@latest -g did nothing, i.e., it remained npm v3.5.2.

I need npm v5.6.0 for a project of mine and is clueless on how to get this issue sorted. Please help.

Upvotes: 4

Views: 11265

Answers (2)

Bret Hess
Bret Hess

Reputation: 502

For me the solution was to make both these links:

sudo ln -s "$(which npm)" /usr/bin/npm

sudo ln -s "$(which node)" /usr/bin/node

See user14219984's answer

Upvotes: 1

LJHarb
LJHarb

Reputation: 39746

(nvm maintainer here)

  1. sudo is not, and must not be, used with nvm. nvm is per-user, per-shell.
  2. npm should not be installed by itself; it comes with node. You should apt-get remove it.
  3. If nvm isn't being loaded properly on a new shell, try rerunning the install script, then file an issue on http://nvm.sh, and I'll be happy to help you directly.

Upvotes: 8

Related Questions