This site runs best with JavaScript enabled.

Dont run npm with sudo

Ian Jones

November 25, 2019


If you install node with root access, npm will ask you to run the sudo command every time you try to install a global package.

The npm docs suggest that you either reinstall npm with a node version manager or change npm's default directory.

It is better, in my opinion, to stay with the default and reinstall with nvm (or your preferred version manager; n is a popular option).

You can run this bash command (as per the documentation) to download nvm:

# you can use curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh | bash
# or wget
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh | bash
Share article