EDIT (2021-2022): Apple's servers now respond with a 302
Redirect to https://developer.apple.com/unauthorized/
Post-apocalypt... er... post-2021 Solution
This short excerpt from my macOS bootstrap.sh
script has been tested as of December 2021.
# Try the AppleScript automation method rather than relying on manual .xip / .dmg download & mirroring
# Note: Apple broke automated Xcode installer downloads. Now requires manual Apple ID sign-in.
# Source: https://web.archive.org/web/20211210020829/https://techviewleo.com/install-xcode-command-line-tools-macos/
xcode-select --install
sleep 1
osascript <<-EOD
tell application "System Events"
tell process "Install Command Line Developer Tools"
keystroke return
click button "Agree" of window "License Agreement"
end tell
end tell
EOD
Old Solutions (pre-2021)
A couple more alternatives may be found at these answers:
Download XCode Command Line Tools
You can download the XCode 4.x CLTools packages from their official download site via direct links.
Here is a script that will automate the install process for you 1.
EDIT (2021-2022): Apple servers now respond with a 302
Redirect to https://developer.apple.com/unauthorized/
when trying to download the CLT packages. Based on this, Apple broke all unattended direct downloads without logging with an Apple ID first. The number of hoops that a script would need to jump through to login, store cookies, and download is prohibitive.
To find updated links for the tools, you can use this command:
curl -Lks https://devimages.apple.com.edgekey.net/downloads/xcode/simulators/index-3905972D-B609-49CE-8D06-51ADC78E07BC.dvtdownloadableindex | plutil -convert json -o - - | python -mjson.tool | less
EDIT (2021-2022): This URL now appears to have broken SSL certificates, and the latest version available is Xcode.CLTools.10.8 version 2014.4
(command_line_tools_for_osx_mountain_lion_april_2014.dmg
)...
Note: The curl
command above now has the -k
flag added to work around this certificate validation issue. Be aware that the -k / --insecure
command line option flag will bypass SSL certificate security checks. This is insecure and there is no way to verify using a PKI + CA chain of trust that this domain is trustworthy and still owned by Apple. It's recommended to use the alternative xcode-select --install
+ osascript
solution above.
[1] Please don't abuse/overload their servers
You may find that it is easier to first Login to the Apple Developer Download Site and download the latest Command Line Tools available there. You can then host the .dmg
on your own package repo server and be able to reliably install the .dmg
on many machines with hdiutil
without having to login to developer.apple.com.
As of 06/10/2015, the link to the latest Command Line Tools dmg
is:
http://adcdownload.apple.com/Developer_Tools/Command_Line_Tools_OS_X_10.10_for_Xcode_6.3.2/commandlinetoolsosx10.10forxcode6.3.2.dmg
EDIT (2021-2022): This URL no longer works... Apple's servers now respond with a 302
Redirect to https://developer.apple.com/unauthorized/
if you are not logged in with an Apple ID.
Please see alternative xcode-select --install
+ osascript
solution above.