npm Command Not Found on Mac? Here's How to Fix It
In this article
If you see command not found: npm on your Mac, it means the npm executable is not installed or not on your shell's PATH. The fastest fix is to install Node.js (which bundles npm) using the official installer or Homebrew, then open a new Terminal window so the PATH updates. Below is the step-by-step process, plus what to do if it still fails.
What You'll Need
- A Mac running macOS (any recent version).
- Administrator access to install software.
- An internet connection.
- Terminal (found in Applications > Utilities).
Step-by-Step
- Check whether Node.js and npm are already installed. Open Terminal and run
node -vandnpm -v. If both return version numbers, npm is installed but your shell may be using a different PATH. If either says “command not found,” continue to the next step. - Install Node.js using the official installer. Go to the official Node.js website and download the macOS installer (LTS version is recommended). Run the .pkg file and follow the prompts. This installs both Node.js and npm system-wide. After installation, quit Terminal completely (Command+Q) and reopen it, then test
npm -vagain. - Alternatively, install via Homebrew. If you use Homebrew, run
brew install nodein Terminal. Homebrew installs npm alongside Node.js. After it finishes, runbrew link --overwrite nodeif needed, then open a new Terminal tab and checknpm -v. - Verify the PATH. If npm is installed but still not found, check where it lives: run
which npm. If it returns nothing, npm is not installed. If it returns a path like/usr/local/bin/npmbut the command still fails, your shell's PATH may not include that directory. For zsh (default on modern macOS), edit~/.zshrcand addexport PATH="/usr/local/bin:$PATH"(or the correct path). Then runsource ~/.zshrc. - Use a Node version manager (optional but recommended for developers). Tools like nvm let you install multiple Node versions and manage npm per project. Install nvm via the official script, then run
nvm install --ltsandnvm use --lts. This avoids permission issues and keeps npm up to date. - Fix permissions if needed. If you previously installed Node with sudo and now get permission errors, avoid using sudo with npm. Instead, reinstall Node via the official installer or nvm, which sets up correct ownership. Never run
sudo npm install -gas a workaround; it can cause further permission problems. - Test npm. Run
npm -vto confirm it works. Then try a simple command likenpm helpto ensure it's fully functional.
Common Mistakes
- Not restarting Terminal after installation. The PATH is loaded when Terminal starts, so changes won't take effect until you open a new window or tab.
- Installing Node.js but not npm. npm comes bundled with Node.js, so if Node is installed correctly, npm should be too. If not, the installation may have failed or been incomplete.
- Using sudo with npm. This can create root-owned files and cause permission errors later. Use a version manager or fix ownership instead.
- Editing the wrong shell profile. macOS uses zsh by default, so edit
~/.zshrc, not~/.bash_profile, unless you've changed your shell. - Assuming Homebrew is installed. Homebrew is not preinstalled on macOS. If you try
brew install nodewithout Homebrew, you'll get a “command not found” for brew. Install Homebrew first from its official site.
Tips
- Use the LTS (Long Term Support) version of Node.js for stability.
- Keep npm updated with
npm install -g npm@latest(avoid sudo). - If you work on multiple projects, consider nvm to switch Node versions easily.
- Check your PATH with
echo $PATHto see which directories are included. - After installing via Homebrew, run
brew doctorto catch common issues.
Troubleshooting
If npm -v still fails after following the steps, try these checks in order:
- Confirm Node.js is installed. Run
node -v. If that also fails, Node.js is not installed or not on your PATH. Reinstall using the official installer. - Check for conflicting installations. You might have Node installed via multiple methods (e.g., official installer and Homebrew). Run
which -a nodeandwhich -a npmto see all paths. Remove duplicates or adjust PATH order. - Look for permission errors. If you see “EACCES” errors when running npm commands, fix ownership of npm's directories. The official npm docs recommend using a version manager or changing the default directory. Avoid sudo.
- Reset PATH temporarily. Run
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"to test if a custom PATH is the issue. If npm works now, your shell profile has a mistake. - Reinstall Node.js. Uninstall any existing Node.js (drag the Node.js app from Applications to Trash, and remove
/usr/local/lib/node_modulesif present), then reinstall from the official installer. - Check for shell issues. If you use a non-standard shell (like fish), ensure you've configured PATH correctly for that shell.
If none of these work, consult the official Node.js and npm documentation for platform-specific guidance.
Frequently Asked Questions
Why does my Mac say “npm: command not found”?
It means npm is either not installed or not in your shell's PATH. Installing Node.js (which includes npm) and restarting Terminal usually fixes it.
Do I need to install npm separately?
No, npm is bundled with Node.js. Installing Node.js via the official installer or Homebrew will also install npm.
Can I use npm without Node.js?
No, npm is the package manager for Node.js and requires Node.js to run.
How do I check if npm is installed?
Open Terminal and type npm -v. If it returns a version number, npm is installed. If not, it's missing.
Why does npm work in one Terminal window but not another?
Different Terminal sessions may load different shell profiles. Ensure your PATH is set consistently in your shell's configuration file (e.g., ~/.zshrc).
Is it safe to use sudo with npm?
No, using sudo with npm can cause permission problems. Use a version manager like nvm or fix directory ownership instead.