Skip to content

How to Fix “Command not found: npm” on Mac/Linux/Windows

2 min read

Introduction



Getting the dreaded error:

…when trying to run an npm command?

You’re not alone. This is one of the most common problems developers face when setting up Node.js or working on a JavaScript project. In this post, we’ll walk you through how to fix this error on macOS, Linux, and Windows.




What is npm?

npm stands for Node Package Manager — it’s bundled with Node.js and lets you install and manage JavaScript libraries and tools.
If your terminal says “npm command not found”, it usually means:

  • Node.js is not installed
  • The installation was incomplete
  • Your system can’t find the npm command



Quick Fix Guide

Follow the steps based on your operating system:




Fix on macOS

Step 1 – Check if Node.js is installed:

bash

If you get “command not found,” Node.js isn’t installed.

Step 2 – Install Node.js with Homebrew:

bash

Once installed, verify:

bash

You should see a version number — that means it worked!





Fix on Linux (Ubuntu/Debian)

Step 1 – Check if Node.js is installed:

bash

Step 2 – Install Node.js and npm:

bash

(Optional – Install latest version):

bash

Verify installation:

bash





Fix on Windows

Step 1 – Download Node.js Installer:

Go to https://nodejs.org and download the LTS version for Windows.

During installation, make sure to check the box that adds Node to PATH.


Step 2 – Verify Installation:

Open Command Prompt or PowerShell:

cmd


If both return version numbers, you’re set!





Still Not Working?

1. Check Your System PATH

If Node is installed but the system can’t find it:

On macOS/Linux, add this to .bashrc or .zshrc:

bash


Then run:

bash


On Windows:

  • Go to System Properties → Advanced → Environment Variables
  • Edit your Path and ensure it includes:

makefile


2. Reinstall Node.js

If nothing else works, reinstall Node.js:

  • Windows: Uninstall via Control Panel → Reinstall from nodejs.org
  • macOS/Linux: Use Homebrew or your package manager to uninstall and reinstall




Final Check

Run:

bash


You should see something like:


That means npm is working correctly!





Pro Tip

To update npm to the latest version globally:

bash





Conclusion

The “Command not found: npm” error is frustrating — but easily fixed with the right steps. Whether you’re on macOS, Linux, or Windows, this guide should have you back up and running quickly.