Skip to content

Instantly share code, notes, and snippets.

@ryanmaclean
Last active November 22, 2023 18:26
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save ryanmaclean/e574a8a0cc16db2cafd1 to your computer and use it in GitHub Desktop.
Save ryanmaclean/e574a8a0cc16db2cafd1 to your computer and use it in GitHub Desktop.
Accept Xcode License on the Command Line
# Run using "sudo accept_xcode_license.sh"
#
# Solving the OSX Yosemite Xcode Command Line Tools Licensing problem
# for multiple updates in order to script post-install tasks.
# Typical error reads after running "xcode-select --install" when setting up
# Homebrew is: "Agreeing to the Xcode/iOS license requires admin priviledges,
# please re-run as root via sudo"
#
# CREDIT:
# Based on a tip found at http://krypted.com/mac-os-x/licensing-the-xcode-command-line-tools/
# Also using the code found here: http://stackoverflow.com/questions/26125036
!/usr/bin/expect
set timeout 5
spawn sudo xcodebuild -license
expect {
"By typing 'agree' you are agreeing" {
send "agree\r\n"
}
"Software License Agreements Press 'space' for more, or 'q' to quit" {
send " ";
exp_continue;
}
timeout {
send_user "\nTimeout 2\n";
exit 1
}
}
expect {
timeout {
send_user "\nFailed\n";
exit 1
}
}
@andybrucenet
Copy link

Hi Ryan - can you check my fork out? I added execute bit to the script and corrected so that the expect shell is properly commented.

Also - when I just ran on Sierra I first had to run:
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

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

After running sudo xcode-select -s ... then your script worked great and accepted the license programmatically no problem. A real help...

@NeskireDK
Copy link

Thank Andy, with that line, specifiying location of Xcode, and then accepting works brilliantly.

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

Copy link

ghost commented Mar 31, 2018

Perfect guys! Thank you!

Just reorder...
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -license accept

@yusufkantar
Copy link

Thanks..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment