sudo npm command not found

0 votes
While using the latest version of node, 

sudo npm install -g n

I get the error:

sudo: npm: command not found

npm works without sudo when I use:

whereis node


I see:

node: /usr/bin/node /usr/lib/node /usr/bin/X11/node /usr/local/node


Running:

which npm


Shows:

/usr/local/node/bin/npm


I have still been getting the same error. I also looked at the /etc/sudoers file and the relevant line is:

Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

This looks fine to me. How can I possibly get NPM working with the sudo command?

Feb 17, 2022 in Others by Soham
• 9,710 points
5,131 views

1 answer to this question.

0 votes

To answer your question, for me, the following line helped me:-

sudo apt-get install npm

answered Feb 17, 2022 by Aditya
• 7,680 points

Related Questions In Others

0 votes
1 answer

'npm' is not recognized as internal or external command, operable program or batch file

To your existing lines of code, include ...READ MORE

answered Feb 10, 2022 in Others by Rahul
• 9,680 points
11,722 views
0 votes
1 answer

'git rev-parse HEAD' is not recognized as an internal or external command

Hi@akhtar, I also faced the same problem. You ...READ MORE

answered Jul 17, 2020 in Others by MD
• 95,460 points
4,155 views
0 votes
0 answers
0 votes
0 answers

Unix xxd -r -p command NodeJS equivalent

I'm attempting to convert an encrypted shell ...READ MORE

Jun 9, 2022 in Node-js by Vaani
• 7,070 points
530 views
0 votes
0 answers

How can I update NodeJS and NPM to their latest versions?

I just installed Node.js & NPM (Node Package Manager) I ...READ MORE

Aug 11, 2022 in Node-js by Neha
• 9,020 points
569 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,945 views
0 votes
1 answer

'adb' is not recognized as an internal or external command, operable program or batch file

Set the path of adb into System ...READ MORE

answered Feb 16, 2022 in Others by Aditya
• 7,680 points
7,174 views
0 votes
1 answer

'composer' is not recognized as an internal or external command in windows server

For anyone coming here from Google who ...READ MORE

answered Feb 17, 2022 in Others by Aditya
• 7,680 points
20,551 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP