Solved “bash: npm: command not found”

in this tutorial, We will discuss different ways to solve the ‘bash: npm: command not found’ error, there are a number of solutions to solve this issue, You can apply one of them to solve the ‘bash: npm: command not found’.

npm(Node Package Manager) is used for the installation and management of JavaScript packages in nodejs application.

I’ll use the following terminology in this tutorial, Let’s understand the role of npm, PATH and Node.js in web development.

Node.js: Node.js is a runtime environment that allows developers to run JavaScript on the server side. It is built on the V8 JavaScript runtime.

npm (Node Package Manager): npm is the default package manager for Node.js, enabling developers to install, share, and manage dependencies in their projects.

PATH variables: This is a list of directories specifying where your computer should look for a program to run from the Terminal.

bash: npm: command not found

Let’s dive into the reasons behind this error and explore the steps to troubleshoot and resolve it.

Case 1: Node.js is Not Installed

Sometimes, Node.js is not installed on your system, we know that npm comes bundled with Node.js, so if Node.js is missing, npm will be absent as well.

You can check using the below command:

node -v
npm -v

The above commands will display the installed versions of Node.js and npm. If you see version numbers, it means Node.js and npm are installed. If not, you need to install Node.js.

Path Variable is not Correct

Please make sure that npm is set up on your PC as a PATH variable. This can happen if the installation path is not included in the system’s PATH environment variable.

First, We’ll verify Path variable values, Open your terminal and run the following command to check if the paths are correctly set:

echo $PATH

If the installation path is not present, you’ll need to add the folder where the npm executable file is located back to the PATH variable. Update the location to the PATH environment variable using the Command Prompt as follows:

SET PATH=C:\Program Files\nodejs;%PATH%

npm Outdated

Sometimes, the npm is outdated, You need to upgrade npm version. The following command is used to update npm to the latest version:

npm install -g npm

This command installs the latest version of npm globally on your system.

Conclusion:

We have investigated several solutions for the “bash: npm: command not found” error. You must confirm that Node.js has been installed completely, check the installation path, and confirm the version of npm. Using a methodical approach will enable you to address the error and fix it.

Leave a Reply

Your email address will not be published. Required fields are marked *