Skip to content

Instantly share code, notes, and snippets.

@MacsInSpace
Forked from mokagio/install-xcode-cli-tools.sh
Last active June 29, 2023 04:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MacsInSpace/5dde6c569e2cb87f5f14293af136a61b to your computer and use it in GitHub Desktop.
Save MacsInSpace/5dde6c569e2cb87f5f14293af136a61b to your computer and use it in GitHub Desktop.
Install Xcode CLI Tools without GUI
#!/bin/bash
# See http://apple.stackexchange.com/questions/107307/how-can-i-install-the-command-line-tools-completely-from-the-command-line
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/.com.apple.dt.CommandLineTools.installondemand.in-progress;
PROD=$(softwareupdate -l |
grep "\*.*Command Line" |
head -n 1 | awk -F"*" '{print $2}' |
sed -e 's/^ *//' |
tr -d '\n')
softwareupdate -i "$PROD" --verbose;
else
echo "Xcode CLI tools OK"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment