nodejs/node · error · Error

Install git and ensure it's in your PATH.

Error message

Install git and ensure it's in your PATH.

What it means

doctor's getGitPath check uses which('git') to locate git; on failure (git not installed or not on PATH) it catches and rethrows this friendly error. Several npm flows (git dependencies) need git, so doctor reports its absence as a failed check.

Source

Thrown at deps/npm/lib/commands/doctor.js:279

        }
      }
    } finally {
      if (!ok) {
        throw (
          `Check the permissions of files in ${root}` +
          (shouldOwn ? ' (should be owned by current user)' : '')
        )
      } else {
        return ''
      }
    }
  }

  async getGitPath () {
    log.info('doctor', 'Finding git in your PATH')
    return await which('git').catch(er => {
      log.warn('doctor', 'getGitPath', er)
      throw new Error("Install git and ensure it's in your PATH.")
    })
  }

  async verifyCachedFiles () {
    log.info('doctor', 'verifyCachedFiles', 'Verifying the npm cache')

    const stats = await cacache.verify(this.npm.flatOptions.cache)
    const { badContentCount, reclaimedCount, missingContent, reclaimedSize } = stats
    if (badContentCount || reclaimedCount || missingContent) {
      if (badContentCount) {
        log.warn('doctor', 'verifyCachedFiles', `Corrupted content removed: ${badContentCount}`)
      }

      if (reclaimedCount) {
        log.warn(
          'doctor',
          'verifyCachedFiles',
          `Content garbage-collected: ${reclaimedCount} (${reclaimedSize} bytes)`

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Install git (apt-get install git, brew install git, etc.)
  2. Ensure the git executable directory is on PATH
  3. For containers, add git to the image (RUN apt-get update && apt-get install -y git)
Defensive patterns

Strategy: validation

Validate before calling

const which = require('which')
function gitAvailable() {
  try { which.sync('git'); return true } catch { return false }
}

Type guard

function hasGitInPath() {
  try { require('which').sync('git'); return true } catch { return false }
}

Prevention

When it happens

Trigger: Running `npm doctor` on a system without git, or where git is installed but not on PATH (minimal Docker images, fresh Windows, sandboxed CI).

Common situations: Slim container images that omit git; Windows without Git for Windows on PATH; sandboxed build environments.

Related errors


AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13). Data as JSON: /api/errors/5393a2f2e58b1e5c. Report an issue: GitHub.