🌐 Detecting your location…
📢 Advertisement — Configure AdSense in Appearance → Customize → AdSense Settings

How to Fix npm command not found After Installing Node.js

⏱️4 min read  ·  774 words

The error npm: command not found (or ‘npm’ is not recognized as an internal or external command on Windows) means your shell can’t locate npm even though you may have installed Node.js. It’s almost always a PATH issue. Here’s how to fix it on every platform.

Why This Happens

npm ships with Node.js. If npm isn’t found, either Node.js didn’t install correctly, or the directory containing npm isn’t in your system’s PATH — the list of locations your shell searches for commands.

Step 1: Verify Node.js Is Actually Installed

# Check if node exists
node --version
# v20.11.0  → Node is installed, npm PATH issue
# command not found → Node itself isn't installed/in PATH

# Check npm
npm --version
which npm    # macOS/Linux — shows npm location
where npm    # Windows

Fix 1: Reinstall Node.js (Simplest)

If neither node nor npm is found, reinstall Node.js properly:

# Download the LTS installer from nodejs.org and run it
# The official installer adds Node and npm to PATH automatically

# Verify after install (open a NEW terminal window)
node --version
npm --version

Important: Always open a new terminal window after installing — PATH changes don’t apply to already-open terminals.

Fix 2: Use nvm (Recommended for Developers)

Node Version Manager handles Node installation and PATH correctly, and lets you switch versions easily:

# macOS/Linux — install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

# Restart your terminal, then:
nvm install --lts      # install latest LTS Node
nvm use --lts          # use it
node --version         # verify
npm --version          # npm comes with it

# Windows — use nvm-windows instead
# Download from github.com/coreybutler/nvm-windows

Fix 3: Add Node to PATH Manually (macOS/Linux)

# Find where node is installed
which node
# /usr/local/bin/node  or  /opt/homebrew/bin/node

# Add its directory to PATH in your shell config
# For zsh (~/.zshrc):
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

# For bash (~/.bashrc or ~/.bash_profile):
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Fix 4: Fix PATH on Windows

# 1. Find Node's install location (usually):
#    C:\Program Files
odejs
# 2. Add to PATH:
#    - Search "Environment Variables" in Start menu
#    - Click "Environment Variables"
#    - Under "System variables", select "Path", click "Edit"
#    - Click "New", add: C:\Program Files
odejs#    - Click OK on all dialogs

# 3. Open a NEW Command Prompt/PowerShell and verify:
node --version
npm --version

Fix 5: Homebrew Node on macOS

# If you installed via Homebrew but it's not found
brew install node

# On Apple Silicon Macs, Homebrew is in /opt/homebrew
# Ensure it's in PATH:
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

# Relink if needed
brew link --overwrite node

Common Cause: Permissions or Global Directory Issues

# If npm works but global installs fail with permission errors,
# configure a user-level global directory (avoids sudo):
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrc
source ~/.zshrc

Frequently Asked Questions

Q: I installed Node but npm still isn’t found. Why?
A: Most commonly, you need to open a NEW terminal window — PATH changes don’t affect already-open terminals. If that doesn’t work, Node’s directory isn’t in your PATH, or the install was incomplete. Reinstall or use nvm.

Q: Should I use nvm or the direct installer?
A: nvm is recommended for developers — it manages PATH correctly, avoids permission issues, and lets you switch Node versions per project. The direct installer is fine for simple single-version setups.

Q: node works but npm doesn’t. How is that possible?
A: Rare, but it can happen if the npm symlink is broken or removed. Reinstall Node.js, or run npm install -g npm if node works. With nvm, reinstall the Node version.

Q: Why do I get permission errors with npm install -g?
A: You’re installing to a system directory that needs admin rights. Never use sudo npm — instead configure a user-level prefix directory (shown above) or use nvm, which avoids the problem entirely.

Q: How do I know which PATH file to edit — .zshrc, .bashrc, or .bash_profile?
A: Check your shell with echo $SHELL. If it’s zsh (default on modern macOS), edit ~/.zshrc. If bash, edit ~/.bashrc (Linux) or ~/.bash_profile (macOS).

Conclusion

“npm: command not found” is a PATH problem: your shell can’t find npm’s location. The quickest reliable fix is installing Node.js via nvm, which handles PATH and permissions correctly and lets you switch versions. Otherwise, reinstall Node from the official installer and always open a new terminal window afterward. If Node is installed but not in PATH, add its directory (found via which node) to your shell config file. Ninety percent of cases resolve by using nvm or opening a fresh terminal.

✍️ Leave a Comment

Your email address will not be published. Required fields are marked *

🌐 Read in:🇬🇧 English🇩🇪 Deutsch🇧🇷 Português🇸🇦 العربية🇮🇳 हिन्दी🇧🇩 বাংলা