Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

npm Command Not Found on Mac? Here's How to Fix It

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

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

  1. Check whether Node.js and npm are already installed. Open Terminal and run node -v and npm -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.
  2. 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 -v again.
  3. Alternatively, install via Homebrew. If you use Homebrew, run brew install node in Terminal. Homebrew installs npm alongside Node.js. After it finishes, run brew link --overwrite node if needed, then open a new Terminal tab and check npm -v.
  4. 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/npm but the command still fails, your shell's PATH may not include that directory. For zsh (default on modern macOS), edit ~/.zshrc and add export PATH="/usr/local/bin:$PATH" (or the correct path). Then run source ~/.zshrc.
  5. 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 --lts and nvm use --lts. This avoids permission issues and keeps npm up to date.
  6. 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 -g as a workaround; it can cause further permission problems.
  7. Test npm. Run npm -v to confirm it works. Then try a simple command like npm help to 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 node without 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 $PATH to see which directories are included.
  • After installing via Homebrew, run brew doctor to catch common issues.

Troubleshooting

If npm -v still fails after following the steps, try these checks in order:

  1. 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.
  2. Check for conflicting installations. You might have Node installed via multiple methods (e.g., official installer and Homebrew). Run which -a node and which -a npm to see all paths. Remove duplicates or adjust PATH order.
  3. 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.
  4. 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.
  5. Reinstall Node.js. Uninstall any existing Node.js (drag the Node.js app from Applications to Trash, and remove /usr/local/lib/node_modules if present), then reinstall from the official installer.
  6. 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.