Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Fix "npm: command not found"

Install Node.js, which includes npm, and make sure it is in your PATH.

VPS and Cloud Servers2 min read7 steps3 screenshots

What npm is

npm is the package manager for Node.js. It installs the libraries your projects need. It comes together with Node.js. If your shell says npm: command not found, Node.js is missing or not in the PATH.

Step 1: Check if it is installed

node -v
npm -v

If both print a version, check your PATH (see below). If not, install Node.js.

Install on Windows

  1. Download the LTS installer from the official Node.js website.
    The Node.js download page
  2. Run the installer. Keep the option Add to PATH ticked.
    The Node.js installer
  3. Open a new Command Prompt and run node -v and npm -v.

Fix the PATH on Windows

If Node.js is installed but npm is not found:

  1. Search for environment variables and open Edit the system environment variables. Click Environment Variables.
  2. Select Path and click Edit.
  3. Make sure the folders C:\Program Files\nodejs\ and %APPDATA%\npm are in the list. Add them if not.
    The Path variable
  4. Open a new Command Prompt.

Install on Linux

Debian and Ubuntu

sudo apt update
sudo apt install nodejs npm

For a newer version, use the NodeSource repository or nvm (Node Version Manager).

CentOS, Rocky and Fedora

sudo dnf install nodejs npm

With nvm (no sudo needed):

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm install --lts

Permission errors

If npm install -g gives a permission error, do not use sudo npm. Change the global folder of npm:

mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

Quick recap

  • Install Node.js, because npm comes with it.
  • Check that the folders are in the PATH.
  • Use nvm to avoid permission problems.