npm command not found (2024)

Npm (node package manager) helps JavaScript developers focus on the code instead of other — sometimes tedious and repetitive — details. Sometimes, however, you may come across npm errors such as 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

GET MATCHED

By continuing you agree to our Terms of Service and Privacy Policy, and you consent to receive offers and opportunitiesfrom Career Karma by telephone, text message, and email.

X

By continuing you agree to our Terms of Service and Privacy Policy, and you consent to receive offers and opportunities from Career Karma by telephone, text message, and email.

What is the npm command not found Error?

The 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:

node -v

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:

npm -v

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.

Update npm

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:

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.

Windows Solution

You may still see npm command not found because C:\Program Files\nodejs could be missing from your PATH environment variable.

  1. Open global search 🔎 and look up “Environment Variables”.
  2. Choose “Edit system environment variables”.
  3. Click “Environment Variables” in the “Advanced” tab.
  4. 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.

Permissions Solution

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.

Conclusion

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.

npm command not found (2024)

FAQs

How do I fix the npm command not found? ›

To fix the npm: command not found error on Windows:
  1. Ensure that npm and Node. js are installed correctly.
  2. Check the PATH and system variables in Windows.
  3. Remove conflicting Node. js installations.
Jun 22, 2023

How to install npm command? ›

How to Install Node.js and NPM on Windows?
  1. Step 1: Download the Installer. Download the Windows Installer from NodeJs official website. ...
  2. Step 2: Install Node.js and NPM. After choosing the path, double-click to install .msi binary files to initiate the installation process. ...
  3. Step 3: Check Node.js and NPM Version.
Feb 14, 2024

Why my npm is not working? ›

There are a few possible reasons why the npm executable might not be in the PATH: npm was not installed correctly: If npm was not installed correctly, it is possible that the executable was not placed in the PATH. This can happen if the installation process was interrupted or if there were issues with the installation.

How to start npm command? ›

The Basics: Getting started with npm
  1. Using npm init to initialize a project.
  2. Using npm init --yes to instantly initialize a project.
  3. Install modules with npm install.
  4. Install modules and save them to your package.json as a dependency.
  5. Install modules and save them to your package.json as a developer dependency.
Feb 10, 2022

How to install npm completely? ›

Installing NPM
  1. Once Node. js is installed, open your terminal or command prompt.
  2. To check if Node. ...
  3. If NPM is not installed or is outdated, you can install it separately or update it by running the command npm install -g npm in the terminal. ...
  4. To verify the NPM installation, type npm -v in the terminal.

How to check if npm is installed? ›

To see if NPM is installed, type npm -v in Terminal. This should print the version number so you'll see something like this 1.4. 28.

What is the npm command? ›

npm is the package manager for the Node JavaScript platform. It puts modules in place so that node can find them, and manages dependency conflicts intelligently. It is extremely configurable to support a variety of use cases. Most commonly, you use it to publish, discover, install, and develop node programs.

Should I install npm or node first? ›

To publish and install packages to and from the public npm registry or a private npm registry, you must install Node.js and the npm command line interface using either a Node version manager or a Node installer. We strongly recommend using a Node version manager like nvm to install Node.js and npm.

How to uninstall npm and reinstall? ›

Reinstall an npm package globally

Uninstalling a global package requires the -g flag and follows the same steps as above: Uninstall the package globally npm uninstall -g <package-name> Install the package globally npm install -g <package-name>

Where is npm installed? ›

On most systems, this is /usr/local . On Windows, it's %AppData%\npm . On Unix systems, it's one level up, since node is typically installed at {prefix}/bin/node rather than {prefix}/node.exe . When the global flag is set, npm installs things into this prefix.

How to use npm without installing? ›

Use npx: npx is a command-line tool that allows you to run npm packages without installing them globally. This is useful for running one-off commands or for testing out new packages without affecting your global environment.

How to run npm command on server? ›

Configuring the Step
  1. Add the Run npm command Step to your Workflow preceding any build Step.
  2. Set the Working directory.
  3. Set the command you want npm to execute, for example install to run npm install in the The npm command with arguments to run input.

How to run npm command from terminal? ›

Otherwise, you can click "Terminal" on the very top and open a new terminal. When you do this, you will get a new window at the bottom of your screen. This window has some tabs, make sure you are in the terminal tab. While there, type "npm init".

How do I run a npm command in a script? ›

To execute your Script, use the 'npm run <NAME-OF-YOUR-SCRIPT>' command. Some predefined aliases convert to npm run, like npm test or npm start, you can use them interchangeably. Maintaining commands you run regularly as an npm script is common, like starting your application, linting, building production apps, etc.

How to force install npm? ›

To force an NPM package to install, you can use the --force flag. This will tell npm to ignore any errors or conflicts that it encounters during installation. You should use the --force flag with caution, as it can lead to unexpected results.

Top Articles
Latest Posts
Article information

Author: Horacio Brakus JD

Last Updated:

Views: 5800

Rating: 4 / 5 (71 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Horacio Brakus JD

Birthday: 1999-08-21

Address: Apt. 524 43384 Minnie Prairie, South Edda, MA 62804

Phone: +5931039998219

Job: Sales Strategist

Hobby: Sculling, Kitesurfing, Orienteering, Painting, Computer programming, Creative writing, Scuba diving

Introduction: My name is Horacio Brakus JD, I am a lively, splendid, jolly, vivacious, vast, cheerful, agreeable person who loves writing and wants to share my knowledge and understanding with you.