npm can't find git on PATH when installing a git dependency. Fix: install Git and reopen your terminal so git is on PATH.
The "spawn git ENOENT" error in npm indicates that Node.js attempted to execute the `git` command but could not find the git executable. ENOENT stands for "Error NO ENTry" - a Unix/Linux error code meaning the file or directory does not exist. When you install npm packages that reference git repositories (using `git://` or `git+https://` URLs), or when packages run post-install scripts that invoke git, npm needs access to the git command-line tool. If git isn't installed or isn't in your system's PATH environment variable, this error occurs. This is most common on Windows systems where git was installed but the PATH wasn't updated, or in Docker containers and CI environments where git wasn't included in the base image. On macOS and Linux, git is often pre-installed or automatically added to PATH, making this error less frequent.
First, check if git is installed and accessible from your terminal:
git --versionIf you see a version number (e.g., git version 2.43.0), git is installed and in your PATH. If you get "command not found" or "'git' is not recognized", git either isn't installed or isn't in your PATH.
On Windows, also try running this in PowerShell:
Get-Command gitThis will show you exactly where git is installed if it's in your PATH.
If git isn't installed, install it for your operating system:
Windows:
1. Download from https://git-scm.com/download/win
2. Run the installer
3. Important: Select "Git from the command line and also from 3rd-party software" during installation
4. Complete the installation and restart your terminal
macOS:
# Using Homebrew (recommended)
brew install git
# Or trigger Xcode Command Line Tools installation
xcode-select --installUbuntu/Debian Linux:
sudo apt update
sudo apt install gitFedora/RHEL/CentOS:
sudo dnf install git
# or for older versions:
sudo yum install gitAlpine Linux (Docker):
apk add --no-cache gitIf git is installed but not in your PATH, add it manually:
1. Find where git is installed. Common locations:
- C:\Program Files\Git\cmd
- C:\Program Files (x86)\Git\cmd
- C:\Users\YourName\AppData\Local\Programs\Git\cmd
2. Open System Properties:
- Press Win + R, type sysdm.cpl, press Enter
- Go to Advanced tab
- Click Environment Variables
3. Under "System variables" (or "User variables"), find Path and click Edit
4. Click New and add the path to git's cmd folder (e.g., C:\Program Files\Git\cmd)
5. Click OK to close all dialogs
6. Important: Close and reopen your terminal, IDE, or restart your computer for changes to take effect
Quick verification:
# After restarting terminal
git --versionEnvironment variable changes only take effect in new terminal sessions. After installing git or modifying PATH:
Terminal:
- Close all terminal windows and open a new one
- On Windows, you may need to log out and back in, or restart
VS Code:
1. Close VS Code completely (check the system tray on Windows)
2. Reopen VS Code
3. Open a new integrated terminal (Ctrl+ or View > Terminal`)
Other IDEs:
- Close and reopen the IDE
- Some IDEs cache environment variables - check IDE settings if the issue persists
After restarting, verify git is accessible:
git --version
npm installIf git works in your system terminal but not in VS Code's integrated terminal, configure the git path explicitly:
1. Open VS Code Settings (Ctrl+, or Cmd+,)
2. Search for "git path"
3. Set Git: Path to the full path of your git executable:
- Windows: C:\Program Files\Git\bin\git.exe
- macOS/Linux: /usr/bin/git or /usr/local/bin/git
Or edit settings.json directly:
{
"git.path": "C:\\Program Files\\Git\\bin\\git.exe"
}4. Restart VS Code after changing this setting
If you're running npm in a Docker container, ensure git is installed in your Dockerfile:
Node.js (Debian-based images):
FROM node:20
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .Node.js Alpine:
FROM node:20-alpine
RUN apk add --no-cache git
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .Note: Install git before running npm install to ensure it's available for git-based dependencies.
If you only need git during the build phase, consider using multi-stage builds to keep your final image smaller.
If you're using Windows Subsystem for Linux (WSL) and experiencing path translation issues:
Option 1: Install git inside WSL:
sudo apt update
sudo apt install gitOption 2: Use Windows git from WSL (if needed):
# Add Windows git to WSL path (in ~/.bashrc or ~/.zshrc)
export PATH="$PATH:/mnt/c/Program Files/Git/cmd"Option 3: Fix path conversion issues:
# Set this environment variable to prevent path conversion issues
export MSYS_NO_PATHCONV=1For best results, use the native Linux git inside WSL rather than the Windows version.
### CI/CD Pipeline Configuration
Ensure git is available in your CI/CD environment:
GitHub Actions:
Git is pre-installed on all GitHub-hosted runners, so this error is rare. If using a custom container, ensure git is installed.
GitLab CI:
before_script:
- apt-get update && apt-get install -y gitCircleCI:
Use an image that includes git, or install it:
steps:
- run: apt-get update && apt-get install -y git### Using Git Bash on Windows
If you're on Windows and having persistent PATH issues, try using Git Bash instead of Command Prompt or PowerShell. Git Bash comes with the Git for Windows installer and has git pre-configured in its PATH.
### npm config for git
You can explicitly set the git path for npm:
npm config set git "C:\Program Files\Git\bin\git.exe"### Debugging PATH Issues
To see your current PATH:
Windows (PowerShell):
$env:PATH -split ';'macOS/Linux:
echo $PATH | tr ':' '\n'Node.js (to see what npm sees):
node -e "console.log(process.env.PATH)"### Alternative: Use HTTPS URLs
If you can't install git but need to install a package from a git repository, some packages offer alternative installation methods:
# Instead of git URL
npm install git+https://github.com/user/repo.git
# Try tarball URL (if available)
npm install https://github.com/user/repo/archive/main.tar.gzHowever, this is a workaround - installing git properly is the recommended solution.
npm error code E401 npm error Incorrect or missing password.
How to fix 'E401 Unable to authenticate' errors with npm private registries
npm notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm
npm ERR! code EUSAGE npm ERR! Usage error
How to fix "npm ERR! code EUSAGE" in Node.js projects