This tutorial will go over the solutions you can try when you encounter the “NPM command not found” error.
What causes this error?
In most cases, this type of error occurs when the system cannot find the path where npm or NodeJS is installed.
This could be because you don’t have npm or NodeJS installed on your system or haven’t configured the PATH to binaries.
Ensure npm is installed
The first step to resolving this type of error is to ensure that you have npm installed on your system.
You only need to install NodeJS as it comes packaged in most cases. To check if NodeJS is installed, run the command:
If NodeJS is installed on your system, the command above should produce the installed Node version.
If you get an error, you do not have it installed on your system.
Installing NodeJS and NPM on Windows
To install npm and NodeJS on your windows system, open your browser and navigate to the resource below:
Select the installer for your system and download it.
Launch the installer package once the download is complete and follow along with the setup wizard.
Under “Custom Setup,” select Add to PATH and set it to “Entire feature will be installed on the local hard drive.”
Follow the following steps, click install a begin the installation process.
Check Node and NPM versions.
Once the installation is complete, open your terminal window and run the commands:
The command above should return the installed Node Version
The above should print the installed npm version.
Windows Manually Add Node and NPM to Path
On Windows, you may face the “npm command not found” error if the path to nodejs and npm are not added to your path variable.
To fix this, locate the path to nodejs and npm binaries.
By default, NodeJS is installed inC:\Program Files\nodejs
Open the command prompt and run the command below to add it to your path
The command above should add the specified directory to the path variable.
Installing NodeJS and NPM on Linux
On Linux, you can use your package manager to install nodejs and npm as shown:
$ sudo apt-get install nodejs npm -y
Once completed, verify nodejs and npm are accessible by checking the versions.
Fix “npm command not found” error – Permissions
In some instances, you may face the “npm command not found” error due to directory permissions.
On Linux, you can fix it by running the commands:
The command above should change the permissions of the npm global package location to the current user.
On macOS, you can run the command:
This article explored various possible causes of the “npm command not found” error. We also dove into details on different methods and techniques you can use to fix it.