Sitemap

Fix“npm: command not found” in Git Bash

5 min readSep 14, 2026

--

While working on a project, I needed to install the project’s dependencies.

I opened Git Bash, navigated to my project directory, and ran:

npm install

Instead of installing the dependencies, I received the following error:

bash: npm: command not found

At first, I assumed there was a problem with npm or my project. However, the error was actually related to my development environment.

In this article, I will walk through how I diagnosed and fixed the npm: command not found error in Git Bash.

Understanding the Error

npm stands for Node Package Manager. It is used to install, manage, and update packages in Node.js projects.

When we run:

npm install

npm reads the project’s package.json file and installs the dependencies required by the project.

The error:

bash: npm: command not found

means that Git Bash cannot find the npm command.

There can be several reasons for this, including:

  • Node.js is not installed.
  • npm is not installed.
  • Node.js was installed, but its location was not added to the system PATH.
  • Git Bash needs to be restarted after installing Node.js.

Since I was using Git Bash, the first thing I needed to determine was whether Node.js and npm were installed on my computer.

Step 1: Check Whether Node.js Is Installed

I checked whether Node.js was available by running:

node -v

Instead of returning a version number, Git Bash showed that the node command was not found.

This confirmed that Node.js was not installed on my computer.

Since npm is installed together with Node.js, the next step was to install Node.js.

Press enter or click to view image in full size

Step 2: Download and Install Node.js

I downloaded Node.js from the official Node.js website.: https://nodejs.org/en/download

I chose the LTS (Long-Term Support) version because it is generally the most stable option for development.

After downloading the installer, I ran it and followed the installation steps.

During installation, I kept the default settings and allowed the installer to complete the setup.

An important part of the installation is ensuring that Node.js is added to the system PATH.

The PATH environment variable allows terminals and command-line tools, including Git Bash, to locate commands such as:

node

and:

npm

Once the installation was complete, I closed Git Bash and opened it again.

Restarting the terminal is important because an existing terminal session may not immediately recognize changes made to the system PATH.

Step 3: Verify the Node.js Installation

After reopening Git Bash, I checked whether Node.js was successfully installed:

node -v

This time, Git Bash returned a version number.

For example:

vXX.X.X

The exact version may be different depending on the version of Node.js installed.

Next, I checked npm:

npm -v

Git Bash also returned an npm version number.

For example:

X.X.X

This confirmed that both Node.js and npm were successfully installed and accessible from Git Bash.

Step 4: Make Sure You Are in the Correct Project Directory

After installing Node.js and npm, I ran:

npm install

However, I encountered a different error:

npm error code ENOENT
npm error enoent Could not read package.json

This error was different from the original:

bash: npm: command not found

The fact that npm returned an error message meant that npm was now successfully installed and working.

The new problem was that npm could not find a package.json file in my current directory.

Get Rachael Muga’s stories in your inbox

Join Medium for free to get updates from this writer.

Before running:

npm install

make sure you are inside the correct project directory because npm looks for a package.json file in the current directory.

The package.json file contains important information about a Node.js project, including its dependencies and scripts.

To check the files in the current directory, I ran:

ls

If the package.json file is not listed, you are likely in the wrong directory.

You can move into the correct project directory using:

cd path/to/your/project

Then check the directory again:

ls

Once you can see:

package.json

you can run:

npm install

Step 5: Run npm install Again

With Node.js and npm successfully installed, I ran:

npm install

This time, Git Bash recognized the command.

npm began reading the project’s package.json file and installing the required dependencies.

After the installation was complete, the project dependencies were available in the project directory.

Depending on the project, npm may create or update files such as:

node_modules/
package-lock.json

The node_modules directory contains the installed project dependencies.

The package-lock.json file helps keep track of the exact versions of installed packages.

What If npm Is Still Not Found?

If Node.js has been installed but Git Bash still displays:

bash: npm: command not found

there are a few things to check.

1. Restart Git Bash

Close all open Git Bash windows and open Git Bash again.

Then run:

node -v
npm -v

2. Check Whether Windows Can Find Node.js

You can also check whether Node.js is available using the Windows Command Prompt or PowerShell.

Run:

node -v
npm -v

If the commands work in PowerShell or Command Prompt but not in Git Bash, the issue may be related to the terminal environment or the system PATH.

3. Check the Node.js Installation Location

On Windows, Node.js is commonly installed in a directory similar to:

C:\Program Files\nodejs\

Git Bash needs access to this location through the Windows PATH environment variable.

After updating the PATH, restart Git Bash and try the commands again.

What I Learned

The error:

bash: npm: command not found

was not caused by my project or by the npm install command itself.

The problem was that Node.js was not installed on my computer.

Since npm is included with Node.js, installing Node.js solved the problem.

My troubleshooting process was:

  1. Run the command that caused the error.
  2. Identify the missing command.
  3. Check whether Node.js is installed.
  4. Install Node.js.
  5. Restart Git Bash.
  6. Verify Node.js using node -v.
  7. Verify npm using npm -v.
  8. Run npm install again.

Conclusion

When I first encountered:

bash: npm: command not found

in Git Bash, the problem appeared to be related to npm.

However, after checking my environment, I discovered that Node.js was not installed.

Installing Node.js also installed npm. After restarting Git Bash and verifying the installation, I was able to run:

npm install

successfully.

The key lesson is that when a terminal says command not found, the first step should be to check whether the software that provides that command is installed and available in your system's PATH.

--

--

Data/Software Quality Assurance Engineer| Cyber Security Analyst