nodejs/node · error · Error

Add ${this.npm.globalBin} to your $PATH

Error message

Add ${this.npm.globalBin} to your $PATH

What it means

doctor's getBinPath check tests whether npm's global bin directory is present in process.env.PATH. If the globalBin path is not a substring of PATH, it throws telling you to add it. Without it, globally installed binaries are not callable.

Source

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

        maxLTS = version
      }

      if (semver.satisfies(version, currentRange) && semver.gt(version, maxCurrent)) {
        maxCurrent = version
      }
    }
    const recommended = semver.gt(maxCurrent, maxLTS) ? maxCurrent : maxLTS
    if (semver.gte(process.version, recommended)) {
      return `current: ${current}, recommended: ${recommended}`
    } else {
      throw `Use node ${recommended} (current: ${current})`
    }
  }

  async getBinPath () {
    log.info('doctor', 'getBinPath', 'Finding npm global bin in your PATH')
    if (!process.env.PATH.includes(this.npm.globalBin)) {
      throw new Error(`Add ${this.npm.globalBin} to your $PATH`)
    }
    return this.npm.globalBin
  }

  async checkCachePermission () {
    return this.checkFilesPermission(this.npm.cache, true, R_OK)
  }

  async checkLocalModulesPermission () {
    return this.checkFilesPermission(this.npm.localDir, true, R_OK | W_OK, true)
  }

  async checkGlobalModulesPermission () {
    return this.checkFilesPermission(this.npm.globalDir, false, R_OK)
  }

  async checkLocalBinPermission () {
    return this.checkFilesPermission(this.npm.localBin, false, R_OK | W_OK | X_OK, true)

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Add the reported globalBin to PATH in your shell rc: export PATH="$(npm config get prefix)/bin:$PATH"
  2. Reinstall/relayout node via nvm so global bins land on PATH automatically
  3. Verify with `echo $PATH` and `npm config get prefix`

Example fix

# before
export PATH="/usr/local/sbin:/usr/bin:/bin"

# after
export PATH="$(npm config get prefix)/bin:$PATH"
Defensive patterns

Strategy: validation

Validate before calling

function globalBinOnPath(globalBin) {
  return process.env.PATH.split(path.delimiter).includes(globalBin)
}

Type guard

function isGlobalBinOnPath(globalBin, p = process.env.PATH) {
  return p.split(path.delimiter).some(dir => path.resolve(dir) === path.resolve(globalBin))
}

Prevention

When it happens

Trigger: Running `npm doctor` after installing node/npm via a method that places global bins outside PATH (custom prefix, manual install, some nvm/homebrew layouts).

Common situations: Custom npm prefix; switching node version managers; sudo-installed npm where globalBin is /usr/local/bin but user PATH omits it.

Related errors


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