MW

How-To · Tools

'npm: command not found' / 'npm is not recognized' — How to Fix on Windows, Mac, Linux (2026)

npm ships bundled with Node.js — if your terminal can't find it, Node.js isn't installed or isn't in PATH. Here's the 3-step fix that works on every OS.

Jan 24, 2025 5 min read Any platform beginner
Advertisement

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:

Command Prompt — Windows
C:\> npm --version
'npm' is not recognized as an internal or external command, operable program or batch file.
Terminal — macOS / Linux
$ npm --version
zsh: command not found: npm

This guide covers all solutions for Windows, macOS, and Linux. By the end your terminal should look like this instead:

Command Prompt — success
C:\> node --version
v20.10.0
C:\> npm --version
10.2.3

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:

  1. Node.js/npm not installed
  2. npm not in system PATH
  3. Corrupted installation
  4. Multiple Node.js versions conflicting
  5. 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:

WindowsC:\Program Files\nodejs\ should contain:

  • node.exe
  • npm.cmd
  • node_modules\npm\

macOS/Linux/usr/local/bin/ should contain:

  • node
  • npm

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:

  1. Press Win + R , type sysdm.cpl
  2. AdvancedEnvironment Variables
  3. System VariablesPathEdit
  4. New → Add: C:\Program Files\nodejs\
  5. OK on all dialogs
  6. 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:

Environment Variables
Variable
Value
ComSpec
C:\WINDOWS\system32\cmd.exe
OneDriveConsumer
C:\Users\mahesh\OneDrive
Path
C:\Windows\system32;C:\Program Files\nodejs\
PATHEXT
.COM;.EXE;.BAT;.CMD;.VBS;.JS
TEMP
C:\Users\mahesh\AppData\Local\Temp

3. Verify PATH:

echo %PATH%

Look for Node.js directory in output.

macOS/Linux PATH Setup

Check current PATH and locate node/npm:

Terminal — locate node + npm
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
$ which node
/usr/local/bin/node
$ which npm
npm not found

If which npm returns nothing, npm’s bin folder isn’t in PATH. Fix it permanently in your shell profile:

Terminal — add npm to PATH permanently
$ echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.zshrc
$ source ~/.zshrc
$ which npm
/usr/local/bin/npm

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:

  1. Uninstall Node.js:

    • Windows: Control Panel → Uninstall
    • macOS: Remove from Applications
    • Linux: sudo apt remove nodejs npm
  2. Download and reinstall from nodejs.org

  3. 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:

  1. Visit npmjs.com
  2. Download npm
  3. 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

Terminal — install via Homebrew
$ brew install node
==> Pouring node--20.10.0.arm64_sonoma.bottle.tar.gz ==> Installed /opt/homebrew/Cellar/node/20.10.0 (2,193 files, 76.4MB)
$ node --version
v20.10.0
$ npm --version
10.2.3

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:

bash — NodeSource LTS install on Ubuntu/Debian
$ curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
## Installing the NodeSource Node.js LTS repo... ## Run sudo apt-get install -y nodejs to install Node.js
$ sudo apt-get install -y nodejs
Setting up nodejs (20.10.0-1nodesource1) ...
$ node --version && npm --version
v20.10.0 10.2.3

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:

  1. Close all terminals
  2. Restart terminal application
  3. Verify PATH: echo $PATH or echo %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:

  1. Clear npm cache: npm cache clean --force
  2. Reinstall npm: npm install -g npm@latest
  3. Check permissions
  4. 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

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

  1. Open antivirus settings
  2. Add exclusions
  3. Add: C:\Program Files\nodejs\
  4. Restart terminal

Prevention Tips

Installation Best Practices

  1. Use Official Installer: Download from nodejs.org
  2. Check “Add to PATH”: During installation
  3. Restart Terminal: After installation
  4. Verify Installation: Test immediately

Maintenance

  1. Keep Updated: Regularly update Node.js and npm
  2. Single Installation: Avoid multiple Node.js versions
  3. Use Version Managers: nvm, fnm for multiple versions
  4. 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

  1. Verify Node.js installed: node --version
  2. Check npm exists: Look for npm in Node.js directory
  3. Verify PATH: Check Node.js directory in PATH
  4. Restart terminal: Close and reopen completely
  5. Reinstall if needed: Use official Node.js installer
  6. Test: npm --version should work

Conclusion

Fixing “npm command not found”:

  1. Verify Node.js is installed (node --version)
  2. Check PATH includes Node.js directory
  3. Restart terminal after PATH changes
  4. Reinstall if installation is corrupted
  5. Use official installer for clean installation

When everything is wired up correctly, you’ll see this:

Command Prompt — fixed
C:\> node --version
v20.10.0
C:\> npm --version
10.2.3
C:\> npm install -g typescript
added 1 package in 2s

npm should work after Node.js is properly installed and in PATH. If issues persist, check for multiple installations or permission problems.

npm Node.js Troubleshooting Command Line Development
Advertisement

Get weekly notes in your inbox

Practical tips, tutorials and resources. No spam.