Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 328
BoumTAC Avatar asked Sep 19 '15 17:09

BoumTAC


People also ask

Can you install npm with NVM?

What is the NVM. The NVM meaning is node version manager, according to the official document, something we can know: This way is more recommend than node installer. You can install and switch between multiple versions of node and npm in your device.

Do I need to use sudo with npm?

Any global installs will cache packages to /root/. npm instead of root -owned files at /home/me/. npm . Just always use sudo -i or sudo -H when running npm install to install global packages and your npm permissions problems will melt away.

Does NVM manage npm?

nvm manages node. js and npm versions. It's designed to be installed per-user and invoked per-shell. nvm works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash), in particular on these platforms: unix, macOS, and windows WSL.


1 Answers

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!

like image 106
LJHarb Avatar answered Oct 11 '22 00:10

LJHarb