How to fix npm ERR! gyp ERR! stack Error: Command failed: xcode-select --print-path in npm

npmINTERMEDIATEHIGHUpdated Dec 3, 2025Β· 117 views

This error occurs when npm tries to build native modules during package installation but cannot find or access Xcode Command Line Tools on macOS. Node-gyp requires Xcode CLT to compile C/C++ dependencies.

Quick fix

Fixes gyp ERR!

xcode-select --print-path
  1. Check current xcode-select path
  2. Reset xcode-select (quick fix)
  3. Install/reinstall Xcode Command Line Tools
  4. Switch to correct developer directory
npm β€” error
xcode-select --print-path
npm ERR! gyp ERR! stack Error: Command failed: xcode-select --print-path

What this error means

When you run `npm install`, some packages contain native C/C++ code that must be compiled. Node-gyp handles this compilation. The error means node-gyp tried to query the Xcode developer directory path but failed. This typically happens because Xcode Command Line Tools are not installed, the developer directory path is misconfigured, or a macOS update invalidated the previous installation.

Typical symptoms

  • npm install stops with gyp ERR! stack Error message
  • npm install fails when packages require native compilation
  • Running `xcode-select --print-path` returns an empty string or error
  • CI/CD pipelines fail during `npm install` on macOS runners
  • Error appears after macOS system update

Common causes

  1. Xcode Command Line Tools are not installed on the system
  2. Command Line Tools were corrupted or partially uninstalled
  3. macOS system update invalidated the CLT installation
  4. Xcode developer directory path is set to wrong location
  5. Both full Xcode and CLT installed with conflicting paths
  6. node-gyp version mismatch with current Python version

How to fix "npm ERR! gyp ERR! stack Error: Command failed: xcode-select --print-path"

1Check current xcode-select path

First, verify what path xcode-select is using:

bash
xcode-select --print-path

If this returns an error or empty string, CLT is missing.

2Reset xcode-select (quick fix)

The simplest solution is resetting xcode-select:

bash
sudo xcode-select --reset

Verify it worked:

bash
xcode-select --print-path

Should show /Applications/Xcode.app/Contents/Developer or /Library/Developer/CommandLineTools. Now try npm install again.

3Install/reinstall Xcode Command Line Tools

If reset didn't work, reinstall CLT:

bash
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install

A popup window will appear. Click 'Install' and wait for completion (10-20 minutes).

4Switch to correct developer directory

If you have full Xcode.app installed, point xcode-select to it:

bash
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

Verify:

bash
xcode-select --print-path
5Manually download Command Line Tools

If automatic installer fails:

1. Visit https://developer.apple.com/download/all/
2. Sign in with your Apple ID
3. Search for 'Command Line Tools'
4. Download the .dmg matching your macOS version
5. Open the .dmg and run the installer
6. Verify with xcode-select --print-path
7. Retry npm install

6Update node-gyp if needed

If using Python 3.12+, you need node-gyp 10+:

bash
npm install -g node-gyp@latest
npm config set node_gyp "/usr/local/lib/node_modules/node-gyp/bin/node-gyp.js"

Retry npm install.

Advanced notes

The xcode-select tool manages the developer directory path used by build tools. After macOS updates (especially major version upgrades), the developer directory path can become stale, requiring reset or reinstall. Most cases can be resolved with sudo xcode-select --reset; full Xcode installation is rarely necessary unless you develop for iOS. If you're in an organization with security software, xcode-select --install may failβ€”in that case, manual download is required.

Frequently asked questions

What does "gyp ERR!" mean?
When you run npm install, some packages contain native C/C++ code that must be compiled. Node-gyp handles this compilation. The error means node-gyp tried to query the Xcode developer directory path but failed.
How do I fix "gyp ERR!"?
This error occurs when npm tries to build native modules during package installation but cannot find or access Xcode Command Line Tools on macOS. Node-gyp requires Xcode CLT to compile C/C++ dependencies.
What causes "gyp ERR!"?
Xcode Command Line Tools are not installed on the system Command Line Tools were corrupted or partially uninstalled macOS system update invalidated the CLT installation
Is the "gyp ERR!" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading