
Homebrew Xcode License Error Fix: Managing macOS Fleets Efficiently
Bo Anderson
Xcode is Apple’s IDE for building apps on macOS, iOS, and other Apple platforms. So if you’re not managing devices for app developers, you might be wondering… why are brew commands failing because of Xcode? Why are users seeing errors about agreeing to the Xcode license?

In this post, we’ll get to the bottom of the sometimes tricky relationship between Xcode and other development environments on macOS. We’ll investigate what causes sudden Xcode issues for your fleet, and finally, provide some tips to help you avoid unexpected blockers.
Are you a Mac Admin trying to resolve recurring Xcode license issues on your fleet? Jump straight to our script for keeping Xcode in check.
More than an IDE
Xcode is not just the graphical app that you use to build Apple apps, it also includes many key development tools such as git and language compilers which don’t come installed in base macOS. Fortunately, Apple realized that not every developer who needs these tools is developing for their platforms, and so created the Xcode command-line tools. This is a slimmed down distribution that includes only the CLI developer tools mentioned above, without the full graphical development environment.
Homebrew usage can depend on several of these tools, depending on how you’re brew‘ing ing. For example, Homebrew needs git for updates, as both Homebrew itself and package definitions are hosted on GitHub. When installing formulae, if you’re building from source, it’s possible that process will require tools that ship with Xcode. Finally, Xcode includes the code signing tools that, as of the transition to Apple Silicon, are required for access to more system functionality.
License to brew
As a key dependency, the Homebrew install script prompts the user to install Xcode command-line tools if they’re not already installed, or if the full Xcode distribution is not installed from the App Store. The problem arises around the license acceptance flow, as the Xcode license must be accepted by the user for both the full Xcode distribution, and the command-line tools. For the command-line tools, a user can accept the license by running the command sudo xcodebuild -license, however, you’ve probably already seen the catch: users must have sudo access to accept the license under both versions of Xcode. Users without sudo will require administrative intervention to accept the license before brew commands are able to be run on their devices, including remote commands executed through Workbrew.
To complicate matters further, accepting the license is not a one-off operation, as the license must be re-accepted every time there’s a new Xcode major version. Users with sudo access can run the license acceptance command again and get back to running brew commands, but restricted users will once again have to escalate to an administrator.
How to accept the Xcode license automatically on every update
The following script will check whether Xcode is waiting for the license to be accepted, and if so, accept it. It also completes the Xcode installation by performing a first launch, which in rare cases, can also cause issues.
if /usr/bin/xcrun -find xcodebuild >/dev/null 2>&1; then
if ! /usr/bin/xcodebuild -license check >/dev/null 2>&1; then
/usr/bin/xcodebuild -license accept
fi
if ! /usr/bin/xcodebuild -checkFirstLaunchStatus >/dev/null 2>&1; then
/usr/bin/xcodebuild -runFirstLaunch
fi
fiDeploy this script via your MDM of choice, ensuring its run with admin privileges, to check for Xcode license issues, and catch them before they halt brew operations. Remember that Xcode updates can come at any time, and set this script to run regularly or as part of your ongoing maintenance scripts. The script only takes action when needed, and so is safe to run repeatedly and frequently.
Whilst you’re at it, why not check out Workbrew? Workbrew integrates with your favorite MDM to give you zero-touch provisioning, automatic inventory syncing, and oversight of brew usage throughout your fleet. Using Workbrew with your MDM is free, and our integration guides help you get set up quickly.