How to fix npm ERR! gyp ERR! stack Error: Agreeing to the Xcode license requires admin privileges in npm
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- Accept Xcode license with sudo
- Alternatively, accept interactively
- Verify Command Line Tools are installed
- Retry your npm install
sudo xcodebuild -license acceptnpm 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
- 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
- Multiple Xcode versions installed with conflicting license states
- 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"
Run the following command to accept the Xcode license agreement:
sudo xcodebuild -license acceptYou'll need to enter your admin password. This accepts the license non-interactively.
If you want to read the license first:
sudo xcodebuild -licenseScroll through the license text (press Space), then type "agree" at the prompt.
Make sure the Command Line Tools are properly installed:
xcode-select --installIf they're already installed, you'll see a message saying so. Otherwise, follow the GUI prompts.
After accepting the license, retry your installation:
npm installNative modules should now compile successfully.
Advanced notes
If you have multiple Xcode versions installed, ensure the correct one is selected:
sudo xcode-select -s /Applications/Xcode.app/Contents/DeveloperFor CI/CD pipelines on macOS, include the license acceptance step in your setup:
- run: sudo xcodebuild -license acceptIf 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
- ๐npm Official Documentation
- ๐Docs: npm install(Official Docs)
- ๐ฌSO: Xcode license agreement(Stack Overflow)
- ๐GitHub: node-gyp Xcode issue(GitHub)