Skip to content

Instantly share code, notes, and snippets.

@lucascantor
Created January 27, 2018 07:58
Show Gist options
  • Save lucascantor/15a98823f81d4d8fee2f15fb317c8cd5 to your computer and use it in GitHub Desktop.
Save lucascantor/15a98823f81d4d8fee2f15fb317c8cd5 to your computer and use it in GitHub Desktop.
Install Xcode Command Line Tools from the command line
#!/bin/bash
# create file to prompt 'softwareupdate' utility to see command line tools as available
/usr/bin/touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
# check for command line tools in available software updates
toInstall=softwareupdate -l | grep -B 1 -E "Command Line (Developer|Tools)" | awk -F"*" '/^ +\\*/ {print $2}' | sed 's/^ *//' | tail -n1
# install this specific software update
/usr/sbin/softwareupdate -i "$toInstall"
# remove temporary file
/bin/rm /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
# configure command line tools installation
/usr/bin/xcode-select --switch /Library/Developer/CommandLineTools
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment