Fix “npm: command not found”

Advertisement

If you’ve encountered the error message “npm: command not found” while working with Node.js, don’t worry! This is a common issue with a straightforward solution. Follow the steps below to troubleshoot and resolve this error.

You are going to see:

Checking npm Installation Checking npm Installation

The first step is to verify whether npm is installed on your system. Open your terminal and enter the following command:

npm -v

You’ll see a version number printed in the terminal if npm is installed. If not, proceed to the next section to install npm.

Top ↑

Installing Node.js and npm Installing Node.js and npm

If npm is not installed, it is likely, that Node.js is also missing from your system. Node.js includes npm by default, so you’ll need to install Node.js to resolve this issue.

MacOS MacOS

Using Homebrew Using Homebrew

If you’re using Homebrew, you can install Node.js and npm with the following command:

brew install node

Top ↑

Using Node Version Manager (NVM) Using Node Version Manager (NVM)

Alternatively, you can use NVM to manage Node.js versions. First, install NVM by running the following command:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

Then, install the latest version of Node.js using NVM:

nvm install node

Top ↑

Windows Windows

To install Node.js on Windows, visit the official Node.js website (https://nodejs.org/) and download the Windows installer. Follow the installation instructions to set up Node.js and npm on your system.

Top ↑

Linux Linux

On Linux, you can use your package manager to install Node.js and npm. For example, on Ubuntu, you can run the following commands:

sudo apt update
sudo apt install nodejs
sudo apt install npm

Top ↑

Verifying npm Installation Verifying npm Installation

After installing Node.js, verify that npm is now available by running the following command:

npm -v

You should see the npm version number in the terminal, indicating a successful installation.

Top ↑

Conclusion Conclusion

By following these steps, you should now have resolved the “npm: command not found” error and have npm installed and working on your system. Happy coding!