Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

node.js

npm

nvm

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.

like image 310
Vaibhav Mishra Avatar asked Oct 14 '25 20:10

Vaibhav Mishra


1 Answers

(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.
like image 60
LJHarb Avatar answered Oct 17 '25 11:10

LJHarb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!