npm: command not found— Fixed [Complete Guide 2026]
⚡ Try This First
Open a brand new terminal window and run:
npm --versionIf that works — your old terminal window just needed refreshing. If not, keep reading.
Why Does npm: command not found Happen?
npm: command not found
# or on Windows:
'npm' is not recognized as an internal or external command,
operable program or batch file.npm ships bundled with Node.js. This error means your terminal cannot find the npm executable. There are four possible reasons, and the fix depends on which one applies to you:
| Cause | Fix |
|---|---|
| Node.js is not installed | Fix 1 or Fix 2 |
| Node installed but PATH not updated | Fix 3 |
| Terminal window was open before install | Fix 5 — open new terminal |
| Windows installer did not add to PATH | Fix 4 |
Diagnose in 30 Seconds
# Step 1: Is Node.js installed?
node --version
# If this returns v20.x.x — Node is installed
# If this also says command not found — Node is NOT installed
# Step 2: Is npm somewhere on your system?
which npm # macOS / Linux
where npm # Windows
# If this returns a path — npm is installed but not in PATH
# If this returns nothing — npm is not installed at allThe single most common cause of this error: you just installed Node.js but are still in the same terminal window that was open before the install. The fix is simply opening a new terminal window.
Install Node.js via nvm (Recommended)
Best permanent fix — handles PATH automaticallynvm (Node Version Manager) is the cleanest way to install Node and npm. It installs everything in your home directory with automatic PATH configuration — no sudo, no permission issues, and you can switch Node versions instantly.
macOS / Linux
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
# Reload your shell config
source ~/.zshrc # zsh (default on macOS)
source ~/.bashrc # bash
# Install latest LTS Node + npm
nvm install --lts
nvm use --lts
# Make it default for all new terminals
nvm alias default node
# Verify both installed
node --version
npm --versionWindows
Windows uses a separate project called nvm-windows. Download the installer from github.com/coreybutler/nvm-windows — it provides the same commands as nvm on Unix.
nvm install lts
nvm use lts
npm --versionnvm installs Node in your home directory (~/.nvm) where you always have full write access — eliminating permission issues forever.
Install Node.js Directly
macOS / Linux / Windows — official installermacOS — via Homebrew
brew install node
# Verify
node --version
npm --versionUbuntu / Debian Linux
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs
# Verify
node --version
npm --versionWindows — official installer
- Download latest LTS installer from nodejs.org
- Run the .msi installer
- Make sure 'Add to PATH' is checked during installation
- Open a NEW terminal window after installation
- Verify: node --version && npm --version
On macOS, do not mix Homebrew Node and nvm Node. Pick one installation method and stick to it — having both causes version conflicts and PATH confusion.
Fix PATH Not Set Correctly
Node is installed but npm still not foundIf node --version works but npm --version says command not found, npm is installed but its location is not in your PATH.
Find where npm is installed
# Find Node's bin directory
node -e "console.log(require('path').dirname(process.execPath))"
# Find npm specifically
find /usr /usr/local -name 'npm' 2>/dev/nullAdd to PATH — macOS / Linux
# Add Node bin to PATH
export PATH="/usr/local/bin:$PATH"
# Or with the path from the command above:
export PATH="/home/youruser/.nvm/versions/node/v20.0.0/bin:$PATH"# Reload shell config
source ~/.zshrc
# Verify
npm --versionAlways open a new terminal after editing PATH — existing windows do not pick up changes until reloaded.
Fix on Windows — Add to PATH
Windows specificOn Windows, npm not found after installing Node.js means the installer did not add Node's directory to the system PATH, or the PATH change has not been picked up by your current terminal.
Check if Node is installed but not in PATH
# Check if Node exists at default location
dir "C:\Program Files\nodejs\npm.cmd"
# If this shows the file, Node is installed — just not in PATHAdd Node to PATH via System Properties
- Press Windows + R, type sysdm.cpl, press Enter
- Click Advanced tab → Environment Variables
- Under System Variables, select Path → click Edit
- Click New and add: C:\Program Files\nodejs
- Click OK on all dialogs
- Open a NEW terminal window
- Verify: npm --version
Or via PowerShell (Administrator)
[Environment]::SetEnvironmentVariable(
"Path",
$env:Path + ";C:\Program Files\nodejs",
"Machine"
)
# Then open new terminal and verify
npm --versionAlways open a brand new terminal window after modifying PATH on Windows. The currently open window will not see the change.
Open a New Terminal Window
After any Node.js installation or PATH changeThis is the most commonly overlooked fix — and solves the problem 40% of the time. When you install Node.js or change PATH, your currently open terminal window does not know about it. The shell loads PATH once when it starts.
# Close your current terminal completely
# Open a brand new terminal window
# Then verify:
node --version
npm --versionOn macOS: Cmd+Q to fully quit Terminal, then reopen it. Just closing the tab is not enough — the parent process must be restarted.
OS-Specific Notes
macOS
macOS Catalina and later uses zsh as the default shell. If you added PATH to ~/.bashrc it will not work — add it to ~/.zshrc instead. After any change run source ~/.zshrc and open a new terminal.
Windows
If you have both a standalone Node.js installation and Node installed via another tool like Chocolatey or winget, they can conflict with each other in PATH. Uninstall all but one and use nvm-windows going forward.
Linux
The apt package for nodejs on Ubuntu is often outdated (sometimes as old as Node 12). Always use the NodeSource repository or nvm to get a current LTS version on Linux.
# Check your Node version
node --version
# If below v18 — upgrade immediately via NodeSource or nvmHow to Prevent This Error
- Use nvm to install Node.js — it handles PATH automatically and lets you switch versions
- Always open a new terminal window after installing Node.js or changing PATH
- On Windows, check 'Add to PATH' during the Node.js installer
- Add a .nvmrc file to projects to pin the Node version: echo '20' > .nvmrc
- On macOS, do not mix Homebrew Node and nvm — pick one
Quick Diagnosis — Work Through in Order
- 1
Open a new terminal window and retry npm --version
Fixes it 40% of the time — try this first
- 2
node --version — does it return a version?
If yes: PATH issue (Fix 3). If no: not installed (Fix 1)
- 3
Install Node via nvm
Best permanent fix for macOS/Linux
- 4
Install via official nodejs.org installer (Windows)
Check Add to PATH during install
- 5
Add Node bin directory to PATH manually
Fix 3 — edit .zshrc or Environment Variables
Frequently Asked Questions
Why does npm command not found happen after installing Node.js?+−
How do I fix npm command not found on Mac?+−
How do I fix npm command not found on Ubuntu Linux?+−
npm not recognized in Windows — how to fix?+−
Node is installed but npm says command not found — why?+−
How do I check if npm is installed correctly?+−
Need Expert Help?
We Build Production-Grade Next.js & Node.js Apps
Softplix is a full-stack development agency. Struggling with Node.js environment issues in production? We can fix your setup.
Talk to an Engineer