Fix“npm: command not found” in Git Bash
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 installInstead of installing the dependencies, I received the following error:
bash: npm: command not foundAt 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 installnpm reads the project’s package.json file and installs the dependencies required by the project.
The error:
bash: npm: command not foundmeans 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 -vInstead 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.
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:
nodeand:
npmOnce 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 -vThis time, Git Bash returned a version number.
For example:
vXX.X.XThe exact version may be different depending on the version of Node.js installed.
Next, I checked npm:
npm -vGit Bash also returned an npm version number.
For example:
X.X.XThis 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 installHowever, I encountered a different error:
npm error code ENOENT
npm error enoent Could not read package.jsonThis error was different from the original:
bash: npm: command not foundThe 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 installmake 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:
lsIf 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/projectThen check the directory again:
lsOnce you can see:
package.jsonyou can run:
npm installStep 5: Run npm install Again
With Node.js and npm successfully installed, I ran:
npm installThis 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.jsonThe 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 foundthere 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 -v2. 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 -vIf 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 foundwas 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:
- Run the command that caused the error.
- Identify the missing command.
- Check whether Node.js is installed.
- Install Node.js.
- Restart Git Bash.
- Verify Node.js using
node -v. - Verify npm using
npm -v. - Run
npm installagain.
Conclusion
When I first encountered:
bash: npm: command not foundin 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 installsuccessfully.
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.







