Skip to content

Instantly share code, notes, and snippets.

@xphir
Last active June 23, 2025 10:18
Show Gist options
  • Select an option

  • Save xphir/bf65c64955ee3adc4853097a2003c7f6 to your computer and use it in GitHub Desktop.

Select an option

Save xphir/bf65c64955ee3adc4853097a2003c7f6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
cli_path="/Library/Developer/CommandLineTools"
flag_file="/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress"
# Create install trigger file if CLI tools are not installed
if [[ ! -d "$cli_path" ]]; then
echo "🔍 Xcode Command Line Tools not found — preparing installation..."
touch "$flag_file"
fi
# Find the latest Command Line Tools product label
product=$(
softwareupdate -l 2>/dev/null |
grep "\*.*Command Line" |
tail -n 1 |
sed 's/^[^C]* //'
)
# Install if a product was found
if [[ -n "$product" ]]; then
echo "⬇️ Installing: $product"
softwareupdate -i "$product" --verbose
# Remove trigger file if it was created
if [[ -f "$flag_file" ]]; then
rm -f "$flag_file"
fi
echo "✅ Xcode Command Line Tools installation complete."
else
echo "✅ Command Line Tools are already up to date."
fi
# bash <(curl -fsSL https://gist.githubusercontent.com/xphir/bf65c64955ee3adc4853097a2003c7f6/raw)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment