Your shell tried to run npm, looked through every directory in your PATH, and came up empty. That's it. That's the whole error. It doesn't necessarily mean npm is missing from your machine — it means the shell can't find it. Two very different problems produce the same message: either npm genuinely isn't installed, or it's sitting on disk somewhere your PATH environment variable doesn't point to. Windows phrases it differently — "'npm' is not recognized as an internal or external command" — but the cause is identical.
Encountering the "npm command not found" error can disrupt your work on Node.js projects. npm, which is the default tool for managing packages in Node.js, is crucial for modern development. If you still don't know what is npm and how to use it to install Node.js packages, you can check our article on this topic. This guide will help you fix the error on Mac, Windows, and Linux by following the steps provided, so you can quickly resolve the issue and ensure that your Node.js projects run smoothly.
🔍 Quick Checks Before You Start
Don't reinstall anything yet. Run these first — they take ten seconds and tell you which fix you actually need.
macOS and Linux
node -v
npm -v
npx -v
which node
which npm
echo $PATH
Windows (PowerShell or Command Prompt)
node -v
npm -v
npx -v
where node
where npm
echo %PATH%
Read the results like this: if node prints a version but npm doesn't, you almost certainly have a PATH or broken-install problem, not a missing runtime. If both fail, Node.js itself isn't installed or isn't reachable. And if the which/where command returns a path but the command still fails, you've got a permissions or symlink issue.
⚠️ Common Causes of the Error
npm is not installed
Most Node.js installers bundle npm, but not all. Some Linux distributions split them into separate packages — Debian and Ubuntu are notorious for this. Installing nodejs from apt without npm leaves you exactly here.
Node.js is installed but npm isn't in PATH
Classic on Windows. The installer wrote files to C:\Program Files\nodejs\ but the PATH entry didn't stick, or you never reopened the terminal.
Multiple Node.js installations are fighting
Homebrew, the official installer, and nvm all in one system? One installation wins the PATH race and its npm symlink is broken or absent.
Your shell profile isn't loading
PATH edits go into .zshrc, .bashrc, or .bash_profile. If you edited the wrong file for your shell, nothing happens. Check which shell you're actually running with the echo $SHELL command — macOS defaults to zsh now, not bash.
nvm is installed but never initialized
nvm is a shell function, not a binary. Non-login shells, IDE terminals, and SSH command sessions often skip the init block entirely, so node and npm vanish.
Permissions or ownership problems
If you've been running sudo npm install -g for years, your npm directories may be root-owned and unreadable by your user account.
🍎 How to Fix npm Command Not Found on macOS
Method 1: Install Node.js with Homebrew (Recommended)
Homebrew streamlines software installations on macOS. If you haven't installed Homebrew yet, initiate the process by executing the following command in your terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Upon successful Homebrew installation, proceed to install Node.js and npm with a single command:
brew update
brew install node
node -v
npm -v
Homebrew paths differ by chip. On Apple Silicon, binaries land in /opt/homebrew/bin. On Intel Macs it's /usr/local/bin. If your PATH only contains the Intel path on an M-series Mac, npm will never be found.
Method 2: Direct Installation from the Official Website
Alternatively, grab the LTS .pkg from the Node.js download page. It installs npm to /usr/local/bin and sets PATH for you. Quit and reopen Terminal afterwards — the running session won't pick up the change.
Still Encountering "npm command not found"?
If you're still encountering the error despite following the steps above, likely npm is not correctly set in your PATH environment variable. Fix it in zsh or bash:
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
which npm
Using bash instead? Same line, but append it to ~/.bash_profile.
How to Fix npm Command Not Found on Windows
Checking and Configuring Environment Variables
In Windows, the system may fail to recognize the npm command due to incorrect or missing environment variables. Begin your process by typing "environment variables" in the search box on the Windows taskbar, then open the "Edit the system environment variables" panel. Expand the "Advanced" tab and click "Environment Variables." In the "System Variables" section, locate and select "Path," then click "Edit."
Add the following entries:
- C:\Program Files\nodejs\
- %APPDATA%\npm — so globally installed CLIs work.
Click OK on every dialog. Then close every terminal window and open a fresh one — environment variables are read when a process starts, so your open PowerShell window will keep failing forever.
Removing Conflicting Node.js Installations
Multiple installations of Node.js or npm on the same system can lead to conflicts. To resolve this, consider removing conflicting installations and retaining only the desired Node.js version. Alternatively, utilize nvm (Node Version Manager) to manage multiple Node.js versions on a single machine. nvm allows users to update and downgrade Node.js versions effortlessly with simple commands.
🐧 How to Fix npm Command Not Found on Ubuntu, Debian, and Linux
Confirm npm Installation
Begin by verifying if npm is installed on your Linux system. Open a terminal window and execute the following command to check the npm version:
sudo npm -v
If you receive the "npm command not found" error, proceed with the installation of Node.js and npm based on your Linux distribution. For a complete walkthrough, see our guide on how to install Node.js on Ubuntu.
Install npm on Ubuntu/Debian
sudo apt update
sudo apt install -y nodejs npm
node -v
npm -v
Distro repos ship older Node.js versions — Ubuntu 22.04 still hands out Node 12 in some channels. For anything modern, use the NodeSource repository or nvm instead.
Install npm on Fedora, RHEL, CentOS, and Rocky Linux
sudo dnf install -y nodejs npm
npm -v
Check PATH Variables
Ensure that the npm installation directory is included in the system's PATH. Execute the following command to check the PATH:
echo $PATH
If the npm installation directory path is not present, update the PATH to include it. Open the .bashrc file using a text editor:
sudo nano ~/.bashrc
Append the following line at the end of the file, replacing /path/to/npm with the actual npm installation directory path:
export PATH="$PATH:/path/to/npm"
Save the file and apply the changes:
source ~/.bashrc
Restart the terminal to complete the PATH update, then verify with:
echo $PATH
Fix Permissions Safely
Rather than chowning system directories, set a user-owned global prefix. It kills sudo-related permission errors permanently:
npm config set prefix ~/.npm-global
echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
🔧 Fixing npm When You Use nvm
nvm needs to be sourced by your shell before node or npm exist. Make sure your profile contains the init block from the nvm repository, then:
command -v nvm
nvm install --lts
nvm use --lts
node -v
npm -v
If command -v nvm prints nothing, the init lines aren't loading. Put them in ~/.zshrc for zsh, ~/.bashrc for interactive bash. And remember: each Node version installed through nvm has its own npm and its own global packages.
💻 Git Bash, VS Code, and "It Works in One Terminal but Not the Other"
Different shells load different startup files, so they end up with different PATH values. That's the entire explanation.
- Git Bash — inherits Windows PATH but uses
~/.bash_profile. If Node was added to PATH after Git Bash was opened, restart it. Still broken? Add the path manually in POSIX form:/c/Program Files/nodejs. - VS Code integrated terminal — VS Code caches the environment from whenever it launched. Fully quit and reopen the editor, not just the terminal panel.
- SSH and CI/CD runners — non-interactive shells skip
.bashrc. Source your nvm init explicitly in the job script, or install Node.js system-wide on the server. If you're setting up a dedicated build environment, our guide on installing Node.js on a Linux VPS walks through it, and a Linux VPS gives you full control over Node.js and npm configuration.
📊 macOS vs Windows vs Linux: Fix at a Glance
| Item | macOS | Windows | Linux |
| Typical npm path | /opt/homebrew/bin or /usr/local/bin |
C:\Program Files\nodejs\ |
/usr/bin or /usr/local/bin |
| PATH check | echo $PATH |
echo %PATH% |
echo $PATH |
| Locate binary | which npm |
where npm |
which npm |
| Where PATH is edited | ~/.zshrc or ~/.bash_profile |
Environment Variables GUI | ~/.bashrc or ~/.zshrc |
| Preferred install | Homebrew or nvm | Official .msi installer | NodeSource or nvm |
✅ Verify the Fix Properly
node -v
npm -v
npx -v
npm config get prefix
Version numbers aren't proof that npm functions. Run a real test:
mkdir npm-test && cd npm-test
npm init -y
npx cowsay "npm works"
If you get a talking cow, you're done. Now's a good time to learn how to update npm to the latest version.
⚠️ Mistakes to Avoid
- Running
sudo npm -vto "check" npm — that tests root's PATH, not yours. - Chaining version checks on one line. They're separate commands.
- Using
sudofor everyday npm work. Fix ownership or set a user prefix instead. - Pasting PATH lines you don't understand. One typo and every command breaks.
- Stacking three installation methods and hoping they cooperate. They won't.
🎯 Final Words
Encountering the "npm command not found" error can be a frustrating roadblock in Node.js development. npm, as the default package manager for Node.js, plays a pivotal role in modern development workflows, simplifying the management of JavaScript packages and dependencies. This troubleshooting guide has equipped you with comprehensive solutions for resolving the error on macOS, Windows, and Linux platforms. By following the provided methods, you can swiftly address common issues such as missing npm installations, incorrect environment variables, conflicting Node.js installations, and insufficient user permissions.


Leave A Comment