Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Install Xcode CLI Tools without GUI
# See
echo "Checking Xcode CLI tools"
# Only run if the tools are not installed yet
# To check that try to print the SDK path
xcode-select -p &> /dev/null
if [ $? -ne 0 ]; then
echo "Xcode CLI tools not found. Installing them..."
touch /tmp/;
PROD=$(softwareupdate -l |
grep "\*.*Command Line" |
head -n 1 | awk -F"*" '{print $2}' |
sed -e 's/^ *//' |
tr -d '\n')
softwareupdate -i "$PROD" -v;
echo "Xcode CLI tools OK"

This comment has been minimized.

Copy link

@damacguy damacguy commented May 25, 2021

First - Thanks for this script!

Second, weirdly on my M1 I'm getting both 12.4 and 12.5 of the command line tools showing up. LOL. But softwareupdate won't let me run the 12.4 (obviously). Another Big Sur (intel) machine only shows 12.5. Very weird. I may see if I can figure out how to choose the 'last' option if multiple are given, assuming that's the latest. I might even try to figure out how to grep the versions and test that to choose. But that all makes my head spin. :-p


This comment has been minimized.

Copy link

@Rodeo314 Rodeo314 commented Sep 6, 2021

FWIW I was using this to install on an old Mojave Mac mini over ssh. softwareupdate didn't recognize the -v option so I had to remove it for it to run.

Still, thanks for the help :-)

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