What the Xcode License Error Means
The error "You have not agreed to the Xcode license agreements" (or its Russian-language variant) appears when attempting to use Xcode, Command Line Tools (xcodebuild, clang, git, and others) on macOS. The system blocks execution, requiring you to accept Apple's license agreement. Typical scenarios include:
- Running
xcodebuildin the terminal. - Using
gitafter installing Xcode. - Building projects via
makeorcmake. - Launching Xcode from the App Store or Dock.
The full error message:
xcodebuild: error: You have not agreed to the Xcode license agreements. Please open Xcode to accept the license agreement, or run `sudo xcodebuild -license` to view and accept the license agreements from the command line.
Causes
- Initial Xcode or Command Line Tools Installation
After installation, the license is not accepted automatically. Explicit confirmation is required. - macOS or Xcode Update
After a major system update (e.g., from macOS Monterey to Ventura) or an Xcode update, the license agreement may reset. - Running Tools Without a Graphical Interface
On servers, in Docker containers, or via SSH, Xcode does not launch in a GUI, so the license cannot be accepted interactively. - Corrupted License Cache
Rarely, the license file in/Library/Developer/CommandLineTools/or~/Library/Developer/may become corrupted. - Using Outdated Command Line Tools
If old tools remain in the system after an Xcode update, they may conflict.
Method 1: Accept License via Terminal (Primary)
This is the fastest and most universal method, working even without a graphical interface.
- Open Terminal
Use Spotlight (Cmd+Space → type "Terminal") or find the app inApplications → Utilities. - Run the license acceptance command
Enter:sudo xcodebuild -license
Press Enter. The system will prompt for the administrator password (characters are not displayed—type blindly). - Scroll Through the License Agreement
Press Space to scroll through the text until the end. After the line appears:By typing 'agree' you are agreeing to the terms of the software license agreements.
Typeagreeand press Enter. - Verify the Result
Run:xcodebuild -version
If the output shows the Xcode version (e.g.,Xcode 15.0), the error is resolved.
⚠️ Important: The
sudocommand requires administrator privileges. Ensure your account has sudo permissions.
Method 2: Accept via Xcode's Graphical Interface
If you have GUI access (e.g., on a workstation), you can accept the license through the Xcode app itself.
- Launch Xcode
Find Xcode in Launchpad or via Spotlight. On first launch, a window with the license agreement appears. - Accept the License
Click Agree in the bottom-right corner of the window. If the window doesn't appear, go to the menu:Xcode → Settings → Locations → Command Line Tools
Select the latest tools version and close settings—Xcode may prompt to accept the license. - Restart Terminal
After accepting the license, close and reopen Terminal for changes to take effect.
Method 3: Force Acceptance for Automation (CI/CD)
In environments without user input (e.g., GitHub Actions, Jenkins), use non-interactive mode.
- Run the command with automatic agreement
sudo xcodebuild -license accept
This command accepts the license without scrolling through the text. Works in Xcode 13+. - For Older Xcode Versions
If-license acceptis unavailable, use:sudo xcodebuild -license < <(echo agree)
This simulates typingagreein interactive mode. - Check in a Script
Add to your CI pipeline:#!/bin/bash if ! xcodebuild -checkFirstLaunchStatus 2>/dev/null; then sudo xcodebuild -license accept fi
The-checkFirstLaunchStatuscommand checks if the license is accepted (available in Xcode 14+).
Method 4: Reinstall Command Line Tools
If the error persists after accepting the license, the tools themselves may be corrupted.
- Remove Current Command Line Tools
sudo rm -rf /Library/Developer/CommandLineTools - Reinstall
xcode-select --install
Or viasoftwareupdate:softwareupdate --install -a - Accept the License
After installation, repeat Method 1.
Prevention
- After updating macOS/Xcode, immediately accept the license via terminal to avoid CI/CD disruptions.
- In deployment scripts, add automatic license acceptance (Method 3) at the beginning.
- For servers, install Xcode or Command Line Tools from a
.pkgpackage and immediately runsudo xcodebuild -license accept. - Regularly check license status in automated environments:
xcodebuild -checkFirstLaunchStatus || echo "License not accepted"
Additional Nuances
Error in Docker Containers
If you're building a macOS-based image (e.g., for testing), add to your Dockerfile:
RUN xcodebuild -license accept
This prevents build failures on first Xcode use.
Multiple Xcode Versions
With multiple Xcode versions installed (e.g., via xcode-select), accept the license for each:
sudo xcodebuild -license -firstLaunch # For active version
sudo xcode-select -s /Applications/Xcode_14.3.app/Contents/Developer
sudo xcodebuild -license -firstLaunch # For second version
sudo Permissions Issues
If sudo xcodebuild -license fails with permission errors, check:
sudo -v # Refreshes sudo cache
dscl . -read /Groups/admin GroupMembership $USER # Checks if user is in admin group
License Acceptance Logging
To confirm the license is accepted, check the file:
cat /var/db/.AppleSetupDone # If file exists, setup is complete
However, the primary indicator is successful output from xcodebuild -version.
Compatibility with Older macOS
On macOS 10.15 (Catalina) and earlier, the -license accept flag may be unavailable. Use interactive mode or update Xcode to version 13+.
Recovery After Failure
If the terminal hangs while scrolling the license, press Ctrl+C and retry the command. Sometimes this helps:
sudo xcodebuild -license < /dev/null
This skips interactive mode but may not work in newer versions.
Conclusion
The Xcode license error is a common issue after installation or updates, but it's resolved with a single command in the terminal. Key points:
- Use
sudo xcodebuild -licensefor interactive acceptance. - In automated environments, use
sudo xcodebuild -license accept. - For frequent issues, check Command Line Tools integrity.
These methods cover 99% of cases on macOS 12+ with Xcode 14+. If the problem persists, verify Xcode is installed correctly and your account has administrator privileges.