How to fix npm ERR! gyp ERR! stack Error: `xcode-select --install` to install the command line tools in npm

npmBEGINNERMEDIUMUpdated Dec 3, 2025ยท 133 views

This error indicates that macOS Command Line Tools are missing, which are required for compiling native Node.js modules. Install them using xcode-select to resolve the issue.

Quick fix

Fixes npm ERR! gyp ERR! stack Error: `xcode-select --install` to install the command line tools

xcode-select --install
  1. Install Command Line Tools
  2. Verify the installation
  3. Retry npm install
  4. If installation fails, reset and retry
npm โ€” error
xcode-select --install
npm ERR! gyp ERR! stack Error: `xcode-select --install` to install the command line tools

What this error means

This error occurs when npm attempts to build a native Node.js module but can't find the necessary compilation tools on your macOS system. Native modules (written in C/C++) need a compiler and related build tools to install. On macOS, these are provided by the Xcode Command Line Tools package, which includes clang, make, and other essential development utilities. The error message helpfully tells you exactly what command to run to fix it.

Typical symptoms

  • npm install fails with gyp ERR! messages
  • Error specifically mentions xcode-select --install
  • Happens when installing packages with native dependencies
  • Occurs on fresh macOS installations or after major OS updates
  • Affects packages like node-gyp, bcrypt, sharp, sqlite3, and canvas

Common causes

  1. Command Line Tools have never been installed on this Mac
  2. macOS was upgraded and Command Line Tools were removed
  3. Xcode was uninstalled, removing the Command Line Tools
  4. Command Line Tools installation is corrupted or incomplete
  5. xcode-select is pointing to an invalid or missing path

How to fix "npm ERR! gyp ERR! stack Error: `xcode-select --install` to install the command line tools"

1Install Command Line Tools

Run the installation command:

bash
xcode-select --install

A dialog will appear asking you to install the tools. Click "Install" and wait for the download to complete (may take several minutes depending on your internet connection).

2Verify the installation

After installation completes, verify the tools are working:

bash
xcode-select -p

This should output something like:

bash
/Library/Developer/CommandLineTools

Also verify gcc is available:

bash
gcc --version
3Retry npm install

Now retry your package installation:

bash
npm install

Native modules should compile successfully.

4If installation fails, reset and retry

If the Command Line Tools installation fails or is corrupted, remove and reinstall:

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

This forces a fresh installation.

Advanced notes

If you have full Xcode installed, you may need to set the correct developer directory:

bash
sudo xcode-select --switch /Library/Developer/CommandLineTools

Or to use Xcode's tools:

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

For headless CI environments, you can install Command Line Tools non-interactively:

bash
touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
softwareupdate -i -a
rm /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress

The Command Line Tools package is about 500MB-1GB, so ensure sufficient disk space.

Frequently asked questions

What does "npm ERR! gyp ERR! stack Error: `xcode-select --install` to install the" mean?
js module but can't find the necessary compilation tools on your macOS system. Native modules (written in C/C++) need a compiler and related build tools to install. On macOS, these are provided by the Xcode Command Line Tools package, which includes clang, make, and other essential development utilities.
How do I fix "npm ERR! gyp ERR! stack Error: `xcode-select --install` to install the"?
This error indicates that macOS Command Line Tools are missing, which are required for compiling native Node.js modules. Install them using xcode-select to resolve the issue.
What causes "npm ERR! gyp ERR! stack Error: `xcode-select --install` to install the"?
Command Line Tools have never been installed on this Mac macOS was upgraded and Command Line Tools were removed Xcode was uninstalled, removing the Command Line Tools
Is the "npm ERR! gyp ERR! stack Error: `xcode-select --install` to install the" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading