How to Fix “npm command not found” Error on Windows, Linux, and Mac

If you’ve just installed Node.js and tried to run an npm command — only to see the dreaded “npm: command not found” or “’npm’ is not recognized as an internal or external command” — don’t worry, this is one of the most common setup issues developers face when starting out with Node.

This error simply means your system can’t find npm (Node Package Manager) in its command-line path. The fix, however, depends on your operating system — whether you’re on Windows, Linux, or macOS.

In this guide, we’ll walk you through exactly why this error occurs and how to fix it step-by-step on each platform.

What Causes the “npm command not found” Error?

The npm command comes bundled with Node.js, so whenever you install Node, npm should be installed automatically.

If npm isn’t recognized, it usually happens because:

  1. Node.js isn’t installed or was installed incorrectly.
  2. npm isn’t added to your system PATH, so the terminal can’t find it.
  3. You’re using a different shell or terminal that doesn’t have access to Node’s environment variables.
  4. The npm installation got corrupted or deleted.

Now let’s fix it for your system.

Fix “npm command not found” on Windows

If you’re on Windows 10 or Windows 11 and see something like:

'npm' is not recognized as an internal or external command,
operable program or batch file.

Follow these steps:

Step 1: Check if Node.js Is Installed

  1. Press Windows + R, type cmd, and hit Enter.
  2. Run this command: node -v
    • If you see a version number like v20.11.0, Node.js is installed.
    • If you see an error saying 'node' is not recognized, you’ll need to reinstall Node.js.

Now check for npm:

npm -v

If that fails, continue below.

Step 2: Reinstall Node.js (with npm)

  1. Go to the official Node.js website.
  2. Download the LTS (Long-Term Support) version for Windows.
  3. Run the installer and check the box that says “Add to PATH” during setup.
  4. Complete installation and restart your computer.

After restarting, open a new Command Prompt or PowerShell window and run:

npm -v

You should now see the npm version number.

Step 3: Manually Add npm to the PATH (if still not working)

Sometimes, npm is installed correctly, but its folder isn’t in your PATH.

  1. Press Windows + S → search for Environment Variables → open Edit the system environment variables.
  2. Click Environment Variables… at the bottom.
  3. Under System variables, select Path → click Edit.
  4. Click New and add the following paths (replace the version numbers if needed): C:\Program Files\nodejs\
  5. Click OKOKOK to save.

Open a new terminal and run:

npm -v

If you see the version, congratulations — npm is fixed!

Fix “npm command not found” on Linux

If you’re on Ubuntu, Debian, Fedora, or any other Linux distro and npm isn’t working, here’s what to do.

Step 1: Install Node.js and npm via Package Manager

Run these commands depending on your Linux distribution:

For Ubuntu / Debian:

sudo apt update
sudo apt install nodejs npm -y

For Fedora:

sudo dnf install nodejs npm -y

After installation, check:

node -v
npm -v

Step 2: If npm Is Still Not Found, Install Node via NodeSource (Recommended)

Sometimes the distro repositories have outdated versions of Node.js.
You can install the latest version using NodeSource:

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs

Then verify:

node -v
npm -v

Step 3: Fix PATH Issues (if npm exists but isn’t recognized)

If you installed Node manually, npm may not be in your PATH.

Run:

which npm

If it returns something like /usr/bin/npm, it’s fine.
If not, find where npm is installed:

find / -name "npm" 2>/dev/null

Then add its directory to your PATH:

export PATH=$PATH:/usr/local/bin

To make this change permanent, add that line to your ~/.bashrc or ~/.zshrc file and run:

source ~/.bashrc

Fix “npm command not found” on macOS

If you’re using macOS and the Terminal says npm: command not found, it’s usually because Node wasn’t installed or added to PATH.

Step 1: Check if Node Is Installed

Run:

node -v

and

npm -v

If both return version numbers, npm is installed correctly. If not, continue.

Step 2: Install Node.js Using Homebrew (Recommended)

If you already have Homebrew installed, this is the easiest method:

brew update
brew install node

Once installed, verify:

node -v
npm -v

Step 3: Manually Add npm to PATH

If npm is installed but not recognized:

sudo nano ~/.zshrc

or (for Bash)

sudo nano ~/.bash_profile

Add this line at the bottom:

export PATH=/usr/local/bin:$PATH

Save and reload your shell:

source ~/.zshrc

Now run:

npm -v

You should see the npm version appear.

Optional: Install Node Version Manager (nvm)

If you frequently switch between Node versions, using nvm (Node Version Manager) prevents most npm-related issues.

For Linux & macOS:

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

For Windows:

You can install nvm for Windows from: https://github.com/coreybutler/nvm-windows

Once installed, run:

nvm install lts
nvm use lts
npm -v

This ensures npm always works with your active Node version.

Common npm Errors and Fixes

Error MessageCauseFix
‘npm’ is not recognized as a commandNode not in PATHAdd Node.js folder to PATH
bash: npm: command not foundNode not installedInstall Node via package manager
npm ERR! code ENOENTMissing npm filesReinstall Node
npm command works in CMD but not PowerShellShell PATH mismatchAdd npm to PowerShell PATH manually

Wrapping Up

And that’s how you fix the “npm command not found” error on Windows, Linux, and Mac.

The main cause is usually that npm isn’t added to your system PATH or wasn’t installed correctly with Node.js. A quick reinstall or PATH update will usually fix it.

If you’re setting up a fresh development environment, we highly recommend using nvm — it simplifies Node management and avoids most npm path issues altogether.

Posted by Arpita

With a background in Computer Science, she is passionate about sharing practical programming tips and tech know-how. From writing clean code to solving everyday tech problems, she breaks down complex topics into approachable guides that help others learn and grow.