npm command not found.
We will work through how to resolve this error, so you can go back to enjoying all that npm has to offer.
Find Your Bootcamp Match
- Career Karma matches you with top tech bootcamps
- Access exclusive scholarships and prep courses
What is the npm command not found Error?
Npm command not found error can appear when you install or upgrade npm.
On Windows, the cause of this error could be that a PATH or system variable is not correctly set. The error can also occur if you do not have npm or Node.js installed, have an outdated version, or have permission issues.
Mac users seeing the npm command not found error could be due to missing files on your computer or a permissions issue.
This article addresses those possible reasons. First we cover general causes related to installation, then go into Mac-specific solutions, before addressing how to fix a potential missing PATH variable on Windows.
Check if npm is Installed
The npm command requires npm to be installed on Windows. Npm uses Node.js, so it comes included in your Node.js installation package. To check if you have NOde.js installed type the following in the terminal:
The -v stands for “version”. Visit the npm site to verify if the version of npm you have installed is the latest version.
You may have accidentally deleted your npm file or moved its location. This can happen more often than you think, especially if you change your PATH on your system.
Check if npm is installed as well as node by typing the following in your terminal:
If you do have npm installed, it will output the version on your computer. To install npm, run the commands here for Mac and here if you are using Windows.
Even though npm comes with Node.js, they are separate, meaning you can have the latest of one and not of the other, since they may have different update release dates.
If you have node (check with $node -v) and your node commands work, you may need to simply update npm. Updating npm can be done with one line:
npm install npm@latest -g
If you have trouble with this command, you may have to prefix it with
sudo npm install -g npm@latest
If you are working on your code in an editor, make sure to restart it after you’re done installing or updating.
You may still see
npm command not found because C:\Program Files\nodejs could be missing from your PATH environment variable.
- Open global search 🔎 and look up “Environment Variables”.
- Choose “Edit system environment variables”.
- Click “Environment Variables” in the “Advanced” tab.
- In the “System Variables” box, search for Path and edit it to include the path C:\Program Files\nodejs. If you don’t see it there click “New” then add this path. (Note: Depending on your version you may just need to edit and append this path to what’s there by prefixing it with a semicolon. You’ll see the other paths there are also separated by semicolons).
Here is some documentation on the Windows settings and environment variables relating to npm in case you are curious and want to read more about the settings.
For permission issues, prefix your terminal commands with
sudo to bypass issues. Permission issues can be the cause of program files not being able to be properly downloaded. You can also try the following terminal commands as a last option if all others have not worked out for you, though this may not be an option for you if you are on a shared or work computer. For Mac and Linux users:
sudo chown -R $(whoami):admin /usr/local/lib/node_modules/
This command adjusts the permissions of the npm directory.
Chown means change owner,
-R means recursively (throughout the files therein), “whoami” grabs your user account name, and the last line is where your node package files are. After running the above command, try the npm command you were attempting again.
After implementing any changes we went through to troubleshoot the “command not found” error, be sure to restart any open code editor or terminal/command prompt. To recap, the suggested solutions we discussed were:
- updating npm
- checking if node is up to date
- fixing the PATH in Windows
- changing permissions for node
This article has instructional links on how to uninstall and install npm for Windows or Mac. If you can do this, it may clear any blockers npm is having.
If you want to dive into npm, read this article on npm which includes curated, proven resources for learning more.
About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers. Learn about the CK publication.