BoumTAC
BoumTAC

Reputation: 3771

impossible to use npm as sudo with nvm

I have install node/npm using the nvm documentation.

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.26.1/install.sh | bash

I then install it:

nvm install stable

and then I have to do:

nvm use node

npm is working but if I want to install a package globally it doesn't work.

sudo npm install -g package

I've got this:

sudo: npm: command not found

I've seen many topic but I didn't really understand anything with symbolic link or something like this. I'm using ubuntu 14.04

Upvotes: 10

Views: 7214

Answers (3)

BoumTAC
BoumTAC

Reputation: 3771

I found the answer in this topic.

It's because I install it using sudo. I have to do those command:

sudo chown -R $USER ~/.npm
sudo chown -R $USER /usr/local/lib/node_module

And now it's work

Upvotes: -1

DevAlien
DevAlien

Reputation: 2476

Why don't you install global packages as a normal user?

npm install -g package

Upvotes: 0

LJHarb
LJHarb

Reputation: 39314

nvm maintainer here - with http://nvm.sh, you should never need to use sudo.

Also, nvm is per-user - meaning, the sudo user won't have it in its shell environment, and its PATH won't be set up properly anyways.

Just do npm install -g package and it will work perfectly :-)

Also, if you do nvm alias default node, you won't have to nvm use every time you open up a new shell!

Upvotes: 9

Related Questions