Last updated: Apr 4, 2024
Reading time·4 min
The error "'npm' is not recognized as an internal or external command, operable program or batch file" occurs for 2 main reasons:
PATH
environment variable.To install Node and add it to your PATH
environment variable:
Next
on the Welcome screen.Next
.Next
.Next
. Notice that there is an "Add to
PATH" option selected.Next
.Install
button.Finish
button.Make sure to close any existing command prompts and PowerShell instances for
the PATH
variable to get updated.
You can start a new CMD shell and use the npm --version
command to make
sure Node is installed.
npm --version node --version
npm
commands for the PATH variable to update.If you got the error in Visual Studio Code and restarting VSCode doesn't help, try to click on the trash bin button to restart the terminal.
If the error persists, add Node to your PATH environment variable manually.
To add Node to your PATH environment variable:
nodejs
directory is most likely under:C:\Program Files\nodejs
C:\Program Files (x86)\nodejs
node.exe
(executable) file.Next, ensure you also have the path to your npm
directory in the PATH as
well.
Your npm
directory is most likely located under
%USERPROFILE%\AppData\Roaming\npm
, which is the same as
C:\Users\YOUR_USER\AppData\Roaming\npm
.
%USERPROFILE%\AppData\Roaming\npm # 👇️ same as below (make sure to replace YOUR_USER with your actual username) C:\Users\YOUR_USER\AppData\Roaming\npm
If you can't find it, try running the npm config get prefix
command.
npm config get prefix
Add the path to npm
and click on "OK" twice to confirm.
Close your Command prompt application and then reopen it.
You might also have to restart your PC, but that's not always necessary.
You can start a new CMD shell and use the npm --version
command to make sure
Node is installed and the npm
command works.
npm --version node --version
If you got the error in Visual Studio Code and restarting VSCode doesn't help, try to click on the trash bin button to restart the terminal.
If the error persists, try to run CMD or VSCode as an administrator before
issuing an npm
command.
To open CMD as an administrator:
Click on the Search bar and type CMD.
Right-click on the Command Prompt application and click "Run as administrator".
You can run VSCode as an administrator by right-clicking on VSCode and clicking "Run as administrator".
Try to issue an npm
command with elevated permissions, e.g. npm --version
.
To solve the error "'npm' is not recognized as an internal or external command, operable program or batch file", make sure:
You can learn more about the related topics by checking out the following tutorials: