How to fix npm ERR! gyp ERR! stack Error: `xcode-select --install` to install the command line tools in npm
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- Install Command Line Tools
- Verify the installation
- Retry npm install
- If installation fails, reset and retry
xcode-select --installnpm 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
- 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
- Command Line Tools installation is corrupted or incomplete
- 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"
Run the installation command:
xcode-select --installA 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).
After installation completes, verify the tools are working:
xcode-select -pThis should output something like:
/Library/Developer/CommandLineToolsAlso verify gcc is available:
gcc --versionNow retry your package installation:
npm installNative modules should compile successfully.
If the Command Line Tools installation fails or is corrupted, remove and reinstall:
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --installThis forces a fresh installation.
Advanced notes
If you have full Xcode installed, you may need to set the correct developer directory:
sudo xcode-select --switch /Library/Developer/CommandLineToolsOr to use Xcode's tools:
sudo xcode-select --switch /Applications/Xcode.app/Contents/DeveloperFor headless CI environments, you can install Command Line Tools non-interactively:
touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
softwareupdate -i -a
rm /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progressThe 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
- ๐npm Official Documentation
- ๐Apple Developer Tools(Official Docs)
- ๐ฌStack Overflow: macOS(Stack Overflow)
- ๐