node.js mac nvm - sudo: npm: command not found

10 Answers

I had to do

sudo apt-get install npm

that worked for me.

bash windows raspberry

I'm trying to upgrade to the latest version of node. I'm following the instructions at

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


which npm



I tried the solution at https://.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?

I had the same problem; here are the commands to fix it:

  • sudo ln -s /usr/local/bin/node /usr/bin/node
  • sudo ln -s /usr/local/lib/node /usr/lib/node
  • sudo ln -s /usr/local/bin/npm /usr/bin/npm
  • sudo ln -s /usr/local/bin/node-waf /usr/bin/node-waf

I had to do the following:

  1. brew update
  2. brew uninstall node
  3. Visit download the file
  4. Install the downloaded file

In order to install npm packages globally with sudo permission, /usr/bin/npm should be available. If npm exists on some other directory, create a soft link like:

sudo ln -s /usr/local/bin/npm /usr/bin/npm

It works on Fedora 25, node8.0.0 and npm5.0.0

If you installed node/npm with nvm, the nvm environment configuration file has to be run before you can use either package.

This is generally found in ~/.nvm/

To run this automatically, include:

source ~/.nvm/

in the .bash_profile file for your user

If you then want to use sudo with that user, make sure to include the -i parameter to make sudo set the user environment. eg

sudo -iu jenkins npm install grunt-cli

I had the same issue,the reason for it was npm package manager was not installed while installing node. This was caused because of the following mistake: In the installation process there is a step called "Custom Setup", here you have the option to choose one of the following: 1) Node.js runtime (This is selected by default). 2) npm package manager 3) Online documentation shortcuts. 4) Add to Path. If you proceed as it is npm package manager will not be installed and hence you will get the error.

Solution: Select npm package manager when you get these options. This worked for me.

If you have downloaded node package and extracted somewhere like /opt you can simply create symbolic link inside /usr/local/bin.

/usr/local/bin/npm -> /opt/node-v4.6.0-linux-x64/bin/npm
/usr/local/bin/node -> /opt/node-v4.6.0-linux-x64/bin/node

Instructions for installing Node.js via package manager for:

  • Arch Linux
  • Debian and Ubuntu based Linux distributions
  • Enterprise Linux and Fedora
  • FreeBSD and OpenBSD
  • Gentoo
  • NetBSD
  • openSUSE and SLE
  • OSX
  • SmartOS and illumos
  • Void Linux
  • Windows

Remove Node completely:

  brew uninstall --force node

Install again:

brew install node;
which node # => /usr/local/bin/node
export NODE_PATH='/usr/local/lib/node_modules'

Installl node.js & simply run

npm install -g bower 

from your project dir