I'm trying to upgrade to the latest version of node. I'm following the instructions at http://davidwalsh.name/upgrade-nodejs
But when I do:
sudo npm install -g n
I get the error:
sudo: npm: command not found
npm works without sudo. When I do:
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 tried the solution at https://stackoverflow.com/a/5062718/1246159
But I'm still 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 sudo command?
sudo /usr/bin/npm install -g n
– robertklep/usr/local/node/bin
to your$PATH
, butnpm
should be installed in/usr/local/bin
. The first directory isn't insecure_path
which explains whysudo
can't find it. – robertklepnvm
on Ubuntu here - with @robertklep comment, I triedsudo /home/${user}/.nvm/version/node/${version}/bin/npm install
and it worked. – Stav Pan Geffen