Skip to main content
Microsoftbeginner

"npm is not recognized as the name of a cmdlet" - How to Fix

Fix "npm : The term 'npm' is not recognized as the name of a cmdlet, function, script file, or operable program" in PowerShell and cmd. Repair your PATH correctly without clobbering it.

6 min readUpdated August 2026

Running npm install in PowerShell and getting "The term 'npm' is not recognized as the name of a cmdlet"? Windows cannot find npm on your PATH. Here is how to fix it properly.

The Error

In PowerShell:

npm : The term 'npm' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:1
+ npm install
+ ~~~
    + CategoryInfo          : ObjectNotFound: (npm:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

In Command Prompt, the same problem reads:

'npm' is not recognized as an internal or external command,
operable program or batch file.

CommandNotFoundException is the key detail. PowerShell is not saying npm failed - it is saying it never found anything to run.


Quick Fix

Close your terminal and open a new one, then:

npm -v

If that prints a version number, you are done. This works because a process reads the PATH environment variable once, at startup, and holds that copy for its entire life. If you installed Node.js while a terminal was already open, that terminal is still working from the PATH as it existed beforehand - including the integrated terminal in VS Code, which needs the whole editor restarted, not just a new terminal tab.

If a fresh terminal still fails, work through the checks below.


Step 1: Is Node.js Installed At All?

node -v
  • Prints a version - Node is installed; skip to step 2.
  • Also not recognized - Node.js is not installed, or not installed for this user.

npm ships with Node.js; it is not a separate download. Install it with either:

winget install OpenJS.NodeJS.LTS

Or download the LTS installer from nodejs.org and leave the "Add to PATH" option checked, which it is by default. Then open a new terminal.


Step 2: Find Out Where npm Is

Get-Command npm -ErrorAction SilentlyContinue
Get-Command node

If node resolves but npm does not, Node.js is installed but npm's directory is missing from your PATH. Check the usual locations:

Test-Path "C:\Program Files\nodejs\npm.cmd"
Test-Path "$env:APPDATA\npm"

C:\Program Files\nodejs\ holds Node itself and the npm launcher. %APPDATA%\npm holds the shims for packages you install globally with npm install -g, so tools like typescript and nodemon need it even when npm itself works.

Inspect what is actually on your PATH:

$env:Path -split ';'

Step 3: Add the Missing Directory to PATH

For the current session only

Useful for confirming the diagnosis before making anything permanent:

$env:Path += ";C:\Program Files\nodejs"
npm -v

If npm works now, PATH was the problem. This change disappears when you close the window.

Permanently, for your user

There is a wrong way to do this that appears in a lot of guides:

# Don't do this
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Program Files\nodejs", "User")

$env:Path is the merged machine and user value. Writing it back into the User scope copies every machine-wide entry into your personal profile, where it is duplicated forever after and can push you past the length limit that silently truncates PATH.

The correct form reads the User scope specifically:

$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
[Environment]::SetEnvironmentVariable("Path", "$userPath;C:\Program Files\nodejs;$env:APPDATA\npm", "User")

Close and reopen your terminal afterwards - the new value is not picked up by processes that are already running.

Advertisement

Through the GUI

If you prefer to see what you are editing: Settings > System > About > Advanced system settings > Environment Variables. Under User variables, select Path, choose Edit, then New, and add C:\Program Files\nodejs and %APPDATA%\npm as separate entries.


Step 4: If You Use nvm-windows

nvm-windows activates a version by repointing a symlink, and no version is active until you select one. A fresh install with nothing selected produces exactly this error.

nvm list
nvm use 20.11.0

nvm use needs an elevated prompt, because it modifies a symlink under C:\Program Files\nodejs. If nvm list shows no versions at all, install one first:

nvm install --lts

Step 5: Check Which Environment You Are In

WSL and Windows keep separate filesystems and separate PATH variables. Node.js installed inside an Ubuntu WSL distribution is invisible to PowerShell, and Node installed on Windows is not the copy WSL will use.

Decide where you want to run the command and install accordingly. Inside WSL:

# Check first
node -v

# Install via the distribution's package manager
sudo apt update && sudo apt install nodejs npm -y

The Ubuntu repositories tend to lag well behind current Node releases, so for real work use nvm inside WSL rather than apt.


Verify the Fix

# Versions
node -v
npm -v

# Which copy is being used
where.exe npm

Expected output:

v20.11.0
10.2.4
C:\Program Files\nodejs\npm
C:\Program Files\nodejs\npm.cmd

where.exe (not the PowerShell where alias) lists every match in PATH order, which is how you spot two competing Node installations - a common state on machines where someone has used both the installer and nvm.


The Error You May Hit Next

Once PATH is fixed, PowerShell may greet you with a different message:

npm : File C:\Program Files\nodejs\npm.ps1 cannot be loaded because running
scripts is disabled on this system.

This is progress: PowerShell found npm, and is now refusing to run its PowerShell shim because the execution policy is Restricted. Fix it with:

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned

That is a separate problem with its own causes and scopes worth understanding before you change anything machine-wide.


Prevention

  • After installing anything that adds to PATH, close every terminal and restart your editor. Most "it did not work" reports are a stale process.
  • Use one version manager or the installer, not both. Mixed installations produce PATH ordering problems that look like this error but are not.
  • Prefer the User scope over the Machine scope for developer tooling; it avoids elevation and keeps other accounts unaffected.
  • Verify with where.exe npm rather than npm -v when troubleshooting, because it shows you which copy answered.

Summary

  1. First: close and reopen the terminal, then run npm -v
  2. Check: node -v to see whether Node.js is installed at all
  3. Locate: Get-Command node and Test-Path "C:\Program Files\nodejs\npm.cmd"
  4. Fix PATH: append to the User scope value, never to $env:Path
  5. nvm users: nvm use <version> from an elevated prompt
  6. Verify: where.exe npm

Frequently Asked Questions

Find answers to common questions

Windows searched every directory in your PATH environment variable and found no executable called npm. Either Node.js is not installed, or it is installed in a location your terminal does not know to look in.

A process reads the PATH environment variable when it starts and keeps that copy for its lifetime. A terminal you opened before installing Node.js is still using the old PATH. Closing and reopening it is genuinely the fix, not a folk remedy.

Run 'node -v' in a fresh terminal. If it prints a version, Node is installed and the problem is limited to npm's location on the PATH. If it also fails, install Node.js - npm ships with it and is not a separate download.

The installer places npm.cmd in 'C:\Program Files\nodejs', and globally installed packages go to '%APPDATA%\npm'. Both directories need to be on your PATH for npm and for the tools you install with it.

Read the User scope value first and append to that, not to $env:Path. $env:Path is the merged machine plus user value, so writing it back into the User scope duplicates every machine entry into your profile and can overflow the length limit.

That is a different error and it means the PATH fix worked. PowerShell found npm and then refused to run its .ps1 shim because the execution policy is Restricted. Run 'Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned'.

WSL and Windows have separate filesystems and separate PATH variables. Node.js installed inside a WSL distribution is invisible to PowerShell, and vice versa. Install it in whichever environment you intend to run commands from.

nvm-windows works by repointing a symlink, and no version is active until you select one. Run 'nvm list' to see what is installed and 'nvm use 20.11.0' from an elevated prompt to activate it.

Command Prompt prints "'npm' is not recognized as an internal or external command, operable program or batch file." Same cause, same fixes - only the wording of the message differs between the two shells.

Open a new terminal and run 'npm -v'. Then run 'where.exe npm' to see exactly which copy is being found, which is useful when multiple Node installations are present.