Solving "npm not recognized as an internal or external command" Error
📋 Table Of Content
In this article, we will see how to resolve the "npm not recognized as an internal or external command" error that occurs when we work or first install our node.
The error occurs when the command prompt is unable to locate the executable npm file in the system, either because the npm is not installed properly or the PATH environment variable is not set properly.
In this article, we will see the different causes of why the error might occur and resolve it and get npm up and running in no time.
Cause of the "npm not recognized" error
The "NPM not recognized as the internal or external command" error occurs due to the following reasons:
- Improper Installation of the Node: npm package is included in Nodejs, so if nodeJs is not properly installed in your system, the command prompt will not be able to detect it and throw us the error.
- Misconfiguration of the PATH environment variable: The PATH environment variable is a system-wide environment variable that contains the list of directories path that contains executable files. And if the path to the npm is not present there, the command prompt will not be able to detect it and it will give us an error.
- Incorrect version of npm : If your system has an older version of npm, it will not be compatible with the newer version of Node.js and this will give the error.
Now, by addressing any of these issues, we can solve the error and get npm to run smoothly again.
Here are some methods that we can use to solve this error.
Method 1: Install NodeJS properly
Make sure that Nodejs is installed properly on your PC. The node package manager (npm) comes with the NodeJS installer. Sometimes if NodeJS is not installed properly it can show the error.
If you have already installed it, you can uninstall it and reinstall the latest version of NodeJS from here:
Get the LTS version of it and install it again in your system. After installing you can verify if the npm (node package manager) is installed correctly by using the command:
You will get the version number in your terminal like this:
Now, if you are still getting the error, then continue with the next step.
Method 2: Adding npm to PATH Environment Variable
If you have properly installed NodeJS on your PC and still getting the error, that means the command prompt is unable to locate the npm executable file.
So, in order to access the executable, we have to add it to the PATH environment variable.
Follow these steps to add the npm path in the Environment variable:
Step1: First get the location where npm is installed in your system using the
where command like this in your command prompt:
Step 2: Next, we have to search for "Edit the system environment variables" in the Startup Menu Search.
Step 3: Now in the System Properties Window, click on the Advanced tab and then click the Environment Variables button.
Step 4: Under System Variables, scroll down and find the Path variable. And click on Edit.
Step 5: Click on New and add the path to the npm executable file (our location is "C:\Program Files\nodejs\npm" as seen in Step1).
Click OK to close all windows.
Once you have added it successfully, you can again check
npm -v and this time the error "npm not recognized as an internal or external command" will be solved.
In this article, we have found out what is the cause of the "npm not recognized command" error and also learned how to solve it by reinstalling the latest version of NodeJS and adding the npm path in the PATH Enviromental Variable.