495

While attempting to compile my C program, running the following command:

gcc pthread.c -o pthread

Returns:

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

and my code does not compile.

Why is this happening and how can I fix this problem?

8
  • 194
    sudo xcodebuild -license Oct 10, 2014 at 4:32
  • 4
    Actually I think the comment of @Andy Barbour is the best answer since the issue can be resolved within the terminal this way. Andy: if you create an answer, I will vote for it.
    – rexford
    Nov 5, 2014 at 10:32
  • 11
    I couldn't even git init without doing this.
    – ruffin
    Nov 25, 2014 at 4:48
  • 2
    This again shows, why OS X is really a great system for the power user...
    – Lukas
    Sep 21, 2015 at 14:34
  • 10
    this answer to a newer, similar question shows how to agree in a fully automated fashion: sudo xcodebuild -license accept - which works on macOS Sierra here, but might not work on earlier versions
    – ssc
    Dec 12, 2016 at 9:41

11 Answers 11

815

Open up Xcode, and accept the new user agreement. This was happening because a new version of Xcode was downloaded and the new agreement was not accepted.

11
  • 84
    Why does this require root, and why isn't anyone bothered by that fact?
    – kbolino
    Sep 8, 2015 at 17:59
  • 1
    @kbolino Installing new software / new versions of software often requires you to enter your user password. When you run the new compiler, you hit that wall.
    – ericsoco
    Sep 22, 2015 at 22:28
  • 23
    @ericsoco, running Xcode should have NOTHING to do with root privileges, whatever excuse there is. It is proper to expect Xcode to be a userland application. Unnecessary root privileges dampen user vigilance and help exploits' proliferation in general. Even if some hardware development or push component wants admin privileges, it should be that component, not the whole dev environment, which requests privileges. Crucially, devs should be able to grant AND revoke those privileges at any point of time. The way it works now looks like a lazy way to architect Xcode on Apple's behalf. Sep 22, 2015 at 23:55
  • 5
    @VladDidenko You don't need admin privileges to run Xcode or git. You need admin privileges to agree to the terms of the Xcode EULA in order to use its applications--which git does (and you did when you installed the application). Privilege escalation here is akin to sites asking for the 3-4 digit security code on the back of your credit card. After agreeing, you don't need admin privileges anymore.
    – user481081
    Sep 26, 2015 at 12:17
  • 13
    @SoldOutActivist Yeah, I know all that. However I use different words to describe it. Like that: It is unreasonable that Apple asks admin privileges to get and record a user consent. Both from the point that It is not trustworthy (any app can make a window like that and time it to Xcode start) and legally questionable (as it seems to bind me for actions of all future users logging into the system). Bad design. Neither Apple nor a user NEED to have the application engineered in a way to demand admin privileges after install is over. Sep 26, 2015 at 22:16
566
sudo xcodebuild -license

will take care of it with no trouble on the command line. Note that you'll have to manually scroll through the license, and agree to its terms at the end, unless you add "accept" to the command line :

sudo xcodebuild -license accept
6
  • 5
    This is elegant. Although I used the other method here, I would actually prefer this one if I saw it first.
    – Vic Jang
    Apr 11, 2015 at 5:37
  • 1
    I get: invalid option --license Jul 3, 2015 at 4:14
  • 5
    There should only be one dash @dan-klasson: -license NOT --license Jul 3, 2015 at 16:23
  • 2
    Maintaining Apple build servers with configuration management and provisioning is not exactly easy, when packages like Xcode and Java JDK requires you to manually accept a license.
    – Saustrup
    Sep 18, 2015 at 12:19
  • 39
    If you are scripting solutions for environments that you control you can also throw in the accept parameter sudo xcodebuild -license accept.
    – tobius
    Sep 28, 2015 at 14:08
114

Got stuck as I was trying to a go get ... I think it was related to git. Here is how was able to fix it ...

  1. I entered the following in terminal:

    sudo xcodebuild -license
    
  2. This will open the agreement. Go all the way to end and type "agree".

That takes care of go get issues.

It was quite interesting how unrelated things were.

2
  • 4
    Yeah I was running git clone on a machine I hadn't used in a minute.
    – Jess
    Oct 6, 2015 at 0:28
  • 4
    You can just press q to quit and agree if not inclined to read it.
    – steve
    Oct 26, 2015 at 12:42
27

Opening XCode and accepting the license fixes the issue.

1
  • I've just hit one after upgrading Xcode to v7.0 etc. and got weird errors considering everything was working prior to the upgrade running Android Studio. This answer worked for me.
    – G O'Rilla
    Sep 20, 2015 at 10:55
15

You don't need to fiddle around with any command :)

Once the XCode is updated, open the Xcode IDE program. Please accept terms and conditions.

You are all set to go :))

7

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

A new version of OSX or XCode was installed and Apple wants you to agree to their Terms and Conditions. So just launch Xcode and "Agree" to them.

1
  • It works, but may not be too apparent to users (like myself) who mainly use tools via the command line instead of the desktop. Would be good if there were some text in Terminal altering users to this.
    – karolus
    Jun 4, 2015 at 15:24
6

I had the same issue, after accepting the license launching XCode or running sudo xcodebuild -license accept i had to restart my Mac – otherwise it did not worked.

1
  • The restart step is crucial. I fumbled around for an hour wondering why it didn't work. I restarted and it all working. Thank you
    – skellertor
    Mar 19, 2020 at 18:09
5

Follow these steps:

  1. Open Terminal.
  2. Enter this command: sudo xcodebuild --license.
  3. Enter system password.
  4. Agree to the license.
1
  • 5
    The flag should only use one dash, i.e., sudo xcodebuild -license.
    – aboutaaron
    Oct 3, 2016 at 19:38
4

I had the same issue when I tried to use git.

It is possible to install git without it. And I doubt that gcc on mac is truly dependent on XCode. And I don't want to use root to accept something unless I'm sure I need it.

I uninstalled XCode by navigating to the applications folder and dragging XCode to the trash.

Now my git commands work as usual. I'll re-install XCode if/when I truly need it.

1
  • 1
    why would using the terminal for a git command require you to accept a license for any non-related application? Or are they related somehow? Nov 11, 2019 at 17:53
2

I'm facing the same issue.

The issue because of X-Code.

Solution: 1. Open X-code and accept user agreement (T&C). or 2. Restart your MAC, It will resolve automatically.

1
  • Welcome to SO! There are many answers with the same solution, could you exposed the benefits of yours? Dec 26, 2019 at 6:49
0

If you have similar issues in Intellij do as others said above me :

  1. Open Terminal.
  2. Enter this command: sudo xcodebuild --license.
  3. Enter system password.
  4. Go to the end of file: Press space(button) to do that.
  5. Type 'Agree' to the license.

And you are done.!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.