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”, 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:
- Node.js isn’t installed or was installed incorrectly.
- npm isn’t added to your system PATH, so the terminal can’t find it.
- You’re using a different shell or terminal that doesn’t have access to Node’s environment variables.
- 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:
1. Check if Node.js Is Installed
Here are the steps you can follow to check if Node.js is installed on your Windows system.
1. Press Windows + R, type cmd, and hit Enter.
2. Run this command: node -v
3. If you see a version number like v20.11.0, Node.js is installed.
4. If you see an error saying 'node' is not recognized, you’ll need to reinstall Node.js.
5. Now check for npm:
npm -v
If that fails, continue below.
2. Reinstall Node.js (with npm)
If node is not recognized on your system you can reinstall Node.js. Here’s how:
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.
5. After restarting, open a new Command Prompt or PowerShell window and run:
npm -v
You should now see the npm version number.
3. Manually Add npm to the PATH
Sometimes, npm is installed correctly, but its folder isn’t in your PATH.
1. Press Windows + S, search for Environment Variables and open Edit the system environment variables.
2. Click Environment Variables… at the bottom.
3. Under System variables, select Path and click Edit.
4. Click New and add the following paths (replace the version numbers if needed):
C:\Program Files\nodejs\
5. Click OK to save.
6. 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.
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
2. If npm Is Still Not Found, Install Node via NodeSource
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
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.
1. Check if Node Is Installed
Run:
node -v
and
npm -v
If both return version numbers, npm is installed correctly. If not, continue.
2. Install Node.js Using Homebrew
If you already have Homebrew installed, this is the easiest method:
brew update
brew install node
Once installed, verify:
node -v
npm -v
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.
Wrapping Up
And that’s how you can fix the “npm command not found” error on Windows, Linux, and Mac.
The issue is usually caused by npm not being added to your system PATH or not being installed correctly with Node.js. In most cases, a quick reinstall of Node.js or updating the PATH variable will solve the problem.
If you’re setting up a fresh development environment, we highly recommend using NVM, as it makes managing Node.js versions easier and helps avoid most npm path-related issues altogether.