
How to Fix “Command not found: npm” on Mac/Linux/Windows
Introduction
Getting the dreaded error:
Command not found: npm
…when trying to run an npm command?
You’re not alone. This is one of the most common problems developers face when setting up Node.js or working on a JavaScript project. In this post, we’ll walk you through how to fix this error on macOS, Linux, and Windows.
What is npm
?
npm
stands for Node Package Manager — it’s bundled with Node.js and lets you install and manage JavaScript libraries and tools.
If your terminal says “npm
command not found”, it usually means:
- Node.js is not installed
- The installation was incomplete
- Your system can’t find the
npm
command
Quick Fix Guide
Follow the steps based on your operating system:
Fix on macOS
Step 1 – Check if Node.js is installed:
bash
node -v
If you get “command not found,” Node.js isn’t installed.
Step 2 – Install Node.js with Homebrew:
bash
brew install node
Once installed, verify:
bash
npm -v
You should see a version number — that means it worked!
Fix on Linux (Ubuntu/Debian)
Step 1 – Check if Node.js is installed:
bash
node -v
Step 2 – Install Node.js and npm:
bash
sudo apt update sudo apt install nodejs npm
(Optional – Install latest version):
bash
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - sudo apt install -y nodejs
Verify installation:
bash
node -v npm -v
Fix on Windows
Step 1 – Download Node.js Installer:
Go to https://nodejs.org and download the LTS version for Windows.
During installation, make sure to check the box that adds Node to PATH.
Step 2 – Verify Installation:
Open Command Prompt or PowerShell:
cmd
node -v npm -v
If both return version numbers, you’re set!
Still Not Working?
1. Check Your System PATH
If Node is installed but the system can’t find it:
On macOS/Linux, add this to .bashrc
or .zshrc
:
bash
export PATH=$PATH:/usr/local/bin
Then run:
bash
source ~/.bashrc
On Windows:
- Go to System Properties → Advanced → Environment Variables
- Edit your
Path
and ensure it includes:
makefile
C:\Program Files\nodejs\
2. Reinstall Node.js
If nothing else works, reinstall Node.js:
- Windows: Uninstall via Control Panel → Reinstall from nodejs.org
- macOS/Linux: Use Homebrew or your package manager to uninstall and reinstall
Final Check
Run:
bash
npm -v
You should see something like:
9.8.1
That means npm
is working correctly!
Pro Tip
To update npm
to the latest version globally:
bash
npm install -g npm
Conclusion
The “Command not found: npm” error is frustrating — but easily fixed with the right steps. Whether you’re on macOS, Linux, or Windows, this guide should have you back up and running quickly.