How to fix npm ERR! gyp ERR! stack Error: Agreeing to the Xcode license requires admin privileges in npm

npmBEGINNERMEDIUMUpdated Dec 3, 2025ยท 182 views

This error occurs when building native Node.js modules on macOS and you haven't accepted the Xcode license agreement. The fix requires running a simple command with admin privileges to accept the license.

Quick fix

Fixes npm ERR! gyp ERR! stack Error: Agreeing to the Xcode license requires admin privileges

sudo xcodebuild -license accept
  1. Accept Xcode license with sudo
  2. Alternatively, accept interactively
  3. Verify Command Line Tools are installed
  4. Retry your npm install
npm โ€” error
sudo xcodebuild -license accept
npm ERR! gyp ERR! stack Error: Agreeing to the Xcode license requires admin privileges

What this error means

This error appears when npm tries to compile native Node.js modules (like node-gyp, bcrypt, or sharp) on macOS, but the Xcode Command Line Tools license hasn't been accepted yet. macOS requires explicit acceptance of Apple's license agreement before development tools can be used. Native modules that need compilation rely on these tools, so the build process fails until the license is accepted. This commonly happens after installing or updating Xcode, upgrading macOS, or on fresh developer machine setups.

Typical symptoms

  • npm install fails with gyp ERR! during native module compilation
  • Error message mentions "Xcode license" and "admin privileges"
  • Build fails specifically on macOS systems
  • Packages like node-sass, bcrypt, sharp, or canvas fail to install
  • Error appears after macOS or Xcode update

Common causes

  1. Xcode Command Line Tools license has never been accepted
  2. Xcode was recently updated and requires re-accepting the license
  3. macOS was upgraded and license acceptance was reset
  4. Multiple Xcode versions installed with conflicting license states
  5. Running npm as non-admin user after Xcode installation

How to fix "npm ERR! gyp ERR! stack Error: Agreeing to the Xcode license requires admin privileges"

1Accept Xcode license with sudo

Run the following command to accept the Xcode license agreement:

bash
sudo xcodebuild -license accept

You'll need to enter your admin password. This accepts the license non-interactively.

2Alternatively, accept interactively

If you want to read the license first:

bash
sudo xcodebuild -license

Scroll through the license text (press Space), then type "agree" at the prompt.

3Verify Command Line Tools are installed

Make sure the Command Line Tools are properly installed:

bash
xcode-select --install

If they're already installed, you'll see a message saying so. Otherwise, follow the GUI prompts.

4Retry your npm install

After accepting the license, retry your installation:

bash
npm install

Native modules should now compile successfully.

Advanced notes

If you have multiple Xcode versions installed, ensure the correct one is selected:

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

For CI/CD pipelines on macOS, include the license acceptance step in your setup:

yaml
- run: sudo xcodebuild -license accept

If you only need Command Line Tools (not full Xcode), you can install them standalone and they have a simpler license process. However, some native modules may still require full Xcode.

Frequently asked questions

What does "npm ERR! gyp ERR! stack Error: Agreeing to the Xcode license requires" mean?
js modules (like node-gyp, bcrypt, or sharp) on macOS, but the Xcode Command Line Tools license hasn't been accepted yet. macOS requires explicit acceptance of Apple's license agreement before development tools can be used. Native modules that need compilation rely on these tools, so the build process fails until the license is accepted.
How do I fix "npm ERR! gyp ERR! stack Error: Agreeing to the Xcode license requires"?
This error occurs when building native Node.js modules on macOS and you haven't accepted the Xcode license agreement. The fix requires running a simple command with admin privileges to accept the license.
What causes "npm ERR! gyp ERR! stack Error: Agreeing to the Xcode license requires"?
Xcode Command Line Tools license has never been accepted Xcode was recently updated and requires re-accepting the license macOS was upgraded and license acceptance was reset
Is the "npm ERR! gyp ERR! stack Error: Agreeing to the Xcode license requires" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading