The “npm command not found” error means your system can’t locate the npm executable. Since npm ships bundled with Node.js, this almost always means Node.js isn’t installed, isn’t in PATH, or got corrupted.
Here’s exactly what it looks like depending on your OS:
This guide covers all solutions for Windows, macOS, and Linux. By the end your terminal should look like this instead:
Understanding the Error
Common Error Messages:
'npm' is not recognized as an internal or external command(Windows)npm: command not found(macOS/Linux)bash: npm: command not found
Root Causes:
- Node.js/npm not installed
- npm not in system PATH
- Corrupted installation
- Multiple Node.js versions conflicting
- Terminal not restarted after installation
Verify Node.js Installation
npm comes bundled with Node.js, so first verify Node.js is installed:
Check Node.js
node --version
If Node.js works but npm doesn’t:
- npm installation is the issue
- Continue to npm-specific solutions
If Node.js also fails:
- Node.js isn’t installed or not in PATH
- Install Node.js first (see npm install guide)
Verify Installation Location
Windows:
where node
where npm
macOS/Linux:
which node
which npm
Expected Locations:
- Windows:
C:\Program Files\nodejs\ - macOS:
/usr/local/bin/(Homebrew) or/usr/bin/ - Linux:
/usr/bin/or/usr/local/bin/
Check npm Installation
Verify npm Exists
Check if npm is installed:
npm --version
If this fails, npm isn’t accessible.
Check npm Location
Find npm executable:
Windows:
dir "C:\Program Files\nodejs\npm.cmd"
macOS/Linux:
ls -la /usr/local/bin/npm
# or
ls -la $(which node)/../lib/node_modules/npm/bin/npm
Verify npm in Node.js Installation
npm should be in the same directory as node:
Windows — C:\Program Files\nodejs\ should contain:
node.exenpm.cmdnode_modules\npm\
macOS/Linux — /usr/local/bin/ should contain:
nodenpm
The npm source tree lives at /usr/local/lib/node_modules/npm/.
PATH Configuration
Windows PATH Setup
1. Find Node.js Installation:
- Usually:
C:\Program Files\nodejs\
2. Add to PATH:
- Press Win + R , type
sysdm.cpl - Advanced → Environment Variables
- System Variables → Path → Edit
- New → Add:
C:\Program Files\nodejs\ - OK on all dialogs
- Restart Command Prompt completely
Here’s what the Environment Variables dialog should look like — the highlighted row is the Node.js path you’re adding:
3. Verify PATH:
echo %PATH%
Look for Node.js directory in output.
macOS/Linux PATH Setup
Check current PATH and locate node/npm:
If which npm returns nothing, npm’s bin folder isn’t in PATH. Fix it permanently in your shell profile:
Use ~/.bashrc instead of ~/.zshrc if you’re on bash (older macOS or most Linux distros).
Reinstall npm
Method 1: Reinstall Node.js
Reinstalling Node.js will reinstall npm:
-
Uninstall Node.js:
- Windows: Control Panel → Uninstall
- macOS: Remove from Applications
- Linux:
sudo apt remove nodejs npm
-
Download and reinstall from nodejs.org
-
Verify installation:
node --version npm --version
Method 2: Install npm Separately
Using npm installer (if Node.js works but npm doesn’t):
curl -L https://www.npmjs.com/install.sh | sh
Or download and install:
- Visit npmjs.com
- Download npm
- Follow installation instructions
Method 3: Update npm
If npm exists but is outdated:
npm install -g npm@latest
If this fails, use Node.js installer to reinstall.
Platform-Specific Solutions
Windows Solutions
Issue: npm.cmd not found
Solution 1: Reinstall Node.js with “Add to PATH” checked
Solution 2: Manually add to PATH (see PATH Configuration above)
Solution 3: Use Node.js installer repair option
Issue: Multiple Node.js installations
where node
Remove old installations and keep only one.
macOS Solutions
Issue: Homebrew installation
This installs both Node.js and npm.
Issue: npm not in PATH after Homebrew
brew link node
Issue: Permission errors
sudo chown -R $(whoami) /usr/local/lib/node_modules
sudo chown -R $(whoami) /usr/local/bin
Linux Solutions
Ubuntu/Debian — the apt repos often ship an older Node. The 2-step NodeSource install is the safer choice:
Fedora/RHEL:
sudo dnf install nodejs npm
Common Issues
Issue: npm Works in Some Terminals But Not Others
Cause: PATH not loaded in that terminal
Solution:
- Close all terminals
- Restart terminal application
- Verify PATH:
echo $PATHorecho %PATH%
Issue: npm Command Works But Fails to Run
Symptoms: npm --version works but npm install fails
Possible Causes:
- Corrupted npm installation
- Permission issues
- Network problems
Solutions:
- Clear npm cache:
npm cache clean --force - Reinstall npm:
npm install -g npm@latest - Check permissions
- Check network/firewall
Issue: Version Mismatch
Node.js and npm versions incompatible:
node --version
npm --version
Solution: Update npm to match Node.js version:
npm install -g npm@latest
Issue: Symlink Problems (macOS/Linux)
Check symlinks:
ls -la $(which npm)
Fix broken symlinks:
sudo rm /usr/local/bin/npm
sudo ln -s /usr/local/lib/node_modules/npm/bin/npm /usr/local/bin/npm
Issue: Antivirus Blocking
Windows: Add Node.js directory to antivirus exclusions
- Open antivirus settings
- Add exclusions
- Add:
C:\Program Files\nodejs\ - Restart terminal
Prevention Tips
Installation Best Practices
- Use Official Installer: Download from nodejs.org
- Check “Add to PATH”: During installation
- Restart Terminal: After installation
- Verify Installation: Test immediately
Maintenance
- Keep Updated: Regularly update Node.js and npm
- Single Installation: Avoid multiple Node.js versions
- Use Version Managers: nvm, fnm for multiple versions
- Backup Configuration: Save PATH settings
Quick Verification Script
Create a test script to verify setup:
#!/bin/bash
echo "Node.js version: $(node --version 2>&1 || echo 'NOT FOUND')"
echo "npm version: $(npm --version 2>&1 || echo 'NOT FOUND')"
echo "Node.js location: $(which node 2>&1 || echo 'NOT FOUND')"
echo "npm location: $(which npm 2>&1 || echo 'NOT FOUND')"
Quick Fix Checklist
- Verify Node.js installed:
node --version - Check npm exists: Look for npm in Node.js directory
- Verify PATH: Check Node.js directory in PATH
- Restart terminal: Close and reopen completely
- Reinstall if needed: Use official Node.js installer
- Test:
npm --versionshould work
Conclusion
Fixing “npm command not found”:
- Verify Node.js is installed (
node --version) - Check PATH includes Node.js directory
- Restart terminal after PATH changes
- Reinstall if installation is corrupted
- Use official installer for clean installation
When everything is wired up correctly, you’ll see this:
npm should work after Node.js is properly installed and in PATH. If issues persist, check for multiple installations or permission problems.