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.
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 npmrather thannpm -vwhen troubleshooting, because it shows you which copy answered.
Summary
- First: close and reopen the terminal, then run
npm -v - Check:
node -vto see whether Node.js is installed at all - Locate:
Get-Command nodeandTest-Path "C:\Program Files\nodejs\npm.cmd" - Fix PATH: append to the User scope value, never to
$env:Path - nvm users:
nvm use <version>from an elevated prompt - Verify:
where.exe npm