Fix: Agreeing to the Xcode/iOS License Requires Admin Privileges

Fix: Agreeing to the Xcode/iOS License Requires Admin Privileges

Written by

in

Quick answer: Run sudo xcodebuild -license accept in Terminal and enter your Mac administrator password to immediately accept the updated Xcode license agreement. Alternatively, open the Xcode app from your Applications folder and click Agree when prompted.

Why this happens

When you run a command like gcc, clang, git, make, or swift in the macOS Terminal, you are not invoking a standalone binary directly. Instead, binaries inside /usr/bin/ such as /usr/bin/gcc are lightweight wrapper stubs managed by xcrun. Every time you run one of those commands, xcrun looks up your active developer directory—usually /Applications/Xcode.app/Contents/Developer—and forwards the command to the toolchain bundled inside Xcode.

Whenever Xcode is installed for the first time or updated to a newer version (for example, automatically in the background through the Mac App Store), Apple often includes a revised Xcode and iOS SDK license agreement. Until an administrator accepts the license for that specific Xcode version, xcrun blocks every tool inside the Xcode bundle from running and exits with:

Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.

Because license acceptance is recorded system-wide for all accounts on the Mac rather than inside a single user folder, standard non-elevated terminal commands cannot record your agreement. Note that the wording please re-run as root via sudo refers to running the Xcode license tool as root—not compiling your project with sudo gcc.

How to fix it

1. Accept the license directly in Terminal (Fastest)

If you want to unblock your compiler and command-line tools right away without opening the Xcode interface or scrolling through pages of legal text, pass the accept argument to xcodebuild.

  1. Open Terminal.
  2. Run the following command:
sudo xcodebuild -license accept
  1. Enter your macOS login password when prompted (nothing will appear on screen as you type) and press Return.

Once the command finishes without output, test your compiler again:

gcc --version

If Apple clang version prints to the console, the license block is cleared and you can compile your program normally:

gcc pthread.c -o pthread

2. Read and accept the license interactively in Terminal

If your organization or workflow requires reviewing the software license terms before accepting them, omit the accept argument to launch the interactive license viewer.

  1. Run xcodebuild with the -license flag:
sudo xcodebuild -license
  1. Press Return to open the agreement in the terminal pager.
  2. Press the Space bar repeatedly to page down to the bottom of the document.
  3. When prompted with By typing 'agree' you are agreeing to the terms of the software license agreements, type agree and press Return.

3. Open Xcode and accept the agreement in the GUI

If you prefer not to use sudo in Terminal, launching the full Xcode application triggers a graphical prompt that handles both the license agreement and any pending first-launch SDK packages.

  1. Open Finder and navigate to /Applications.
  2. Double-click Xcode to launch it.
  3. When the license agreement window appears, click Agree.
  4. Enter an administrator username and password when macOS asks to authorize the changes.
  5. If Xcode asks to install additional required components or platform support, let that step finish before returning to Terminal.

4. Fix active developer directory mismatches with xcode-select

In two common situations, sudo xcodebuild -license accept will either fail or seem unnecessary:

Case A: xcodebuild says it requires Xcode

If running sudo xcodebuild -license accept returns:

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

your active path points to the standalone Command Line Tools, or an environment variable like DEVELOPER_DIR is overriding it. Check both:

xcode-select -p
echo $DEVELOPER_DIR

If you want to use your full Xcode installation in /Applications/Xcode.app, point xcode-select to it and then accept the license:

sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -license accept

Case B: You only need gcc, make, or git—not full Xcode

If an outdated or unused copy of Xcode.app is sitting in /Applications, every App Store update to it will re-trigger the Xcode/iOS license prompt even if you never develop iOS or macOS apps. If you only write C, C++, Python, or web software and already have Apple’s standalone Command Line Tools installed, switch your active toolchain away from full Xcode:

sudo xcode-select --switch /Library/Developer/CommandLineTools

If /Library/Developer/CommandLineTools does not exist yet on your Mac, install the standalone package with:

xcode-select --install

Click Install in the macOS dialog and agree to the Command Line Tools license window once.

How to prevent it

  • Never run your build command with sudo: Running sudo gcc pthread.c -o pthread might trigger an interactive prompt or fail awkwardly, and any compiled binaries or object files it creates will be owned by root, causing Permission denied errors on future builds.
  • Disable automatic App Store updates on build machines: If a background App Store update upgrades Xcode mid-week, automated scripts, Git hooks, and package managers like Homebrew will fail until someone accepts the new license. Open App Store > Settings and uncheck Automatic Updates on machines dedicated to CLI work.
  • Automate acceptance on self-hosted CI runners: When provisioning macOS CI/CD agents or running scripts that upgrade Xcode, always run sudo xcodebuild -license accept as a post-install step before starting your build runner service.
  • Launch Xcode once right after updating: Whenever you manually update Xcode, open the app immediately so license acceptance and system component updates complete before you start a coding session.

FAQ

Why am I getting an Xcode/iOS license error when compiling C code with gcc?

On macOS, /usr/bin/gcc is not GNU GCC—it is an Apple shim that invokes Clang from your active Xcode toolchain. Because gcc routes through Xcode’s developer tools, macOS requires the Xcode license agreement to be accepted before the compiler will run.

Should I run sudo gcc like the error message says?

No. The message please re-run as root via sudo comes from the underlying Xcode license check, not from the compiler itself. Run sudo xcodebuild -license accept once to satisfy the license requirement, then run gcc as your normal user.

How do I fix this on a managed work or school Mac without sudo access?

Because accepting the Xcode license writes to system-level preferences, a standard macOS user account cannot bypass or accept it alone. Ask your IT administrator either to run sudo xcodebuild -license accept remotely via MDM (such as Jamf or Kandji) or to grant temporary elevated privileges so you can accept the prompt.

Sources & credits

Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.