keepcalculator

06 Numbers and Powers

Npm Command Not Found? Fix It in 5 Minutes

Card No. 06·65578 · Updated · Standard formula, shown below

The calculator on this card is switched off while it is checked. The formula is below, and the worked example shows how to do the sum by hand.

If you see npm: command not found in your terminal, it usually means Node.js is not installed or its bin directory is not in your system’s PATH. The fix is to install Node.js (which bundles npm) or adjust your PATH, and this article walks you through both.

What Is npm and Why Does It Go Missing?

npm (Node Package Manager) is the default package manager for Node.js. It installs, updates, and manages JavaScript libraries and tools from the npm registry. When you run npm in a terminal, the shell looks for an executable file named npm in the directories listed in your PATH environment variable. If it doesn’t find one, it prints command not found (on macOS/Linux) or 'npm' is not recognized (on Windows).

Common reasons npm is missing:

  • Node.js is not installed at all.
  • Node.js is installed but npm is not included (rare, but possible with some minimal builds).
  • npm is installed but its directory is not in your PATH.
  • You’re using a version manager (like nvm) and haven’t activated a Node version.
  • The npm executable is corrupted or symlinked incorrectly.

Check If Node.js Is Installed

Before installing anything, verify whether Node.js is present. Run these commands in your terminal:

node -v
npm -v

If node -v prints a version like v20.11.0, Node.js is installed. If npm -v fails, npm is missing or misconfigured. If node -v also fails, Node.js itself is not installed.

Sometimes Node.js is installed but npm is not in PATH. On macOS/Linux, npm typically lives in the same bin directory as node. On Windows, it’s usually in the same folder as node.exe.

Install Node.js (Which Includes npm)

The simplest fix is to download and install the latest LTS (Long-Term Support) version of Node.js from the official website (nodejs.org). The installer sets up both Node.js and npm, and adds them to your PATH automatically.

Windows

  1. Download the Windows Installer (.msi) from nodejs.org.
  2. Run the installer. Accept the license, choose the default installation path (e.g., C:\Program Files\nodejs), and keep the default options.
  3. After installation, open a new terminal window (important – the PATH is updated for new sessions only) and run npm -v.

macOS

You can download the macOS Installer (.pkg) from nodejs.org, or use Homebrew:

brew install node

Homebrew installs Node.js and npm and links them into /usr/local/bin (or /opt/homebrew/bin on Apple Silicon), which is already in PATH.

Linux

Most distributions have Node.js in their repositories, but the version may be old. For a current version, use NodeSource:

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs

Or use nvm (Node Version Manager) to install and manage multiple Node versions:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
nvm install --lts
nvm use --lts

After any installation, close and reopen your terminal, then test with npm -v.

Fix PATH Issues Without Reinstalling

If Node.js is installed but npm is not recognized, the problem is likely your PATH. Here’s how to check and fix it.

Windows

  1. Open System Properties (right-click This PC → Properties → Advanced system settings).
  2. Click Environment Variables.
  3. Under User variables, select Path and click Edit.
  4. Add the directory where npm is installed (e.g., C:\Program Files\nodejs). If you’re not sure, search for npm.cmd on your system.
  5. Click OK and open a new terminal.

macOS/Linux

Check your shell’s PATH with echo $PATH. The npm directory (usually /usr/local/bin or /usr/bin) should be listed. If not, add it to your shell profile. For bash, add this line to ~/.bashrc:

export PATH="/usr/local/bin:$PATH"

For zsh, add it to ~/.zshrc. Then run source ~/.bashrc (or source ~/.zshrc) or restart the terminal.

If You Use a Version Manager (nvm, fnm, n)

Version managers let you switch between Node versions. If you use nvm, you must activate a version before npm works. Run:

nvm ls
nvm use node

If nvm is installed but the command is not found, you may need to reload your shell profile:

source ~/.bashrc

If nvm itself is missing, reinstall it using the official script from the nvm GitHub repository (search for “nvm-sh/nvm”).

Common Mistakes and Misconceptions

One frequent mistake is running npm in a terminal that was opened before the installation. The PATH is only updated for new terminal sessions. Always open a fresh terminal after installing Node.js.

Another misconception is that npm is a separate download. It is bundled with Node.js, so installing Node.js is the primary fix. However, if you have a custom Node installation (e.g., compiled from source), npm might not be included. In that case, install npm separately using curl -qL https://www.npmjs.com/install.sh | sh (but this is rare and not recommended).

On Windows, sometimes the PATH entry points to a directory that doesn’t exist (e.g., if you uninstalled an older Node version). Clean up your PATH by removing stale entries.

Frequently Asked Questions

Why does npm work in one terminal but not another?

This is almost always a PATH issue. Each terminal session reads the PATH from the environment at launch. If you installed Node.js after opening a terminal, that terminal won’t see the new PATH. Close and reopen the terminal, or run source ~/.bashrc (or ~/.zshrc) to reload the profile.

I installed Node.js but npm is still not found. What now?

Check if npm exists in the Node.js installation directory. On Windows, look for npm.cmd in the same folder as node.exe. On macOS/Linux, run which npm – if it returns nothing, npm is not installed. Reinstall Node.js using the official installer, making sure to select the option to add to PATH. If you used a version manager, activate a Node version first.

Can I use npm without installing Node.js?

No. npm is part of the Node.js ecosystem and requires Node.js to run. There is no standalone npm installer that works without Node.js. You must install Node.js, which includes npm.

How do I update npm to the latest version?

Once npm is working, you can update it with: npm install -g npm@latest. This installs the latest version globally. On Windows, you may need to run the command as Administrator. On macOS/Linux, you might need sudo if your global npm directory is not writable.

What if I see “npm: not found” in a script or cron job?

Cron jobs and scripts often run with a minimal environment that doesn’t include the full PATH. In your script, use the full path to npm (find it with which npm) or set the PATH at the top of the script, e.g., export PATH="/usr/local/bin:$PATH". For cron, you can also specify the PATH in the crontab.

Is it safe to install Node.js from the official website?

Yes, the official Node.js website (nodejs.org) provides signed installers for Windows, macOS, and Linux. Always download from the official site to avoid malicious versions. For Linux, using the official package repositories or NodeSource is also safe.

Related

Formula used

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →