8

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

BoumTAC
  • 3,531
  • 6
  • 32
  • 44

3 Answers3

9

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!

LJHarb
  • 32,486
  • 2
  • 32
  • 38
  • 3
    So if I don't have to use sudo how do i overcome this issue: Error: EACCES: permission denied when trying to access .npm in my home – BoumTAC Sep 19 '15 at 17:09
  • You may have installed node/npm with sudo prior to using `nvm`. My recommendation is to sudo chown your entire home directory so that you own it, and uninstall the system version of node/npm. – LJHarb Sep 20 '15 at 22:48
  • @LJHarb npm start need admin privileges. but cannot run with sudo. what to do then? – bazi Nov 03 '17 at 11:47
  • @bazi Why would `npm start` ever need admin privileges? Perhaps https://thomashunter.name/blog/using-authbind-with-node-js/ would be helpful for you. – LJHarb Nov 04 '17 at 18:04
  • I need sudo specifically because `npm install -g package` isn’t solving my problem, and I need to `npm i package` in a particular directory. – Calion Jul 01 '22 at 13:17
  • then put a package.json there, and `npm install` will install it in that directory's node_modules. If you're trying to set up a package in a way that's fighting node ecosystem conventions, you're going to have a bad time. – LJHarb Jul 02 '22 at 17:54
0

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

npm install -g package
DevAlien
  • 2,456
  • 15
  • 17
  • 1
    because I have Error: EACCES: permission denied when trying to access .npm in my home – BoumTAC Sep 19 '15 at 17:09
  • Because it was created earlier with sudo. try deleting the folder (just rename it) and then do the various `npm install -g package` – DevAlien Sep 19 '15 at 17:13
-1

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

Community
  • 1
  • 1
BoumTAC
  • 3,531
  • 6
  • 32
  • 44
  • When using `nvm`, `/usr/local/lib/node_module` shouldn't be used either. Do you have a `prefix` set in `~/.npmrc`? if so, please remove it. – LJHarb Sep 20 '15 at 00:23