Created
October 15, 2024 10:19
-
-
Save zencd/c479b037ab8ecdd6616968dc5ff1bc38 to your computer and use it in GitHub Desktop.
install xcode command line tools from command line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function install_xcode_command_line_tools_if_not_yet() { | |
# install xcode cli tools via terminal | |
# try the gui installer if failed | |
# original hack: https://github.com/Homebrew/install/blob/master/install.sh | |
if xcode-select -p 1>/dev/null 2>&1; then | |
return | |
fi | |
installed=0 | |
tmp_file=/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress | |
touch "$tmp_file" | |
label=$(softwareupdate -l | grep -B 1 -E 'Command Line Tools' | awk -F'*' '/^ *\\*/ {print $2}' | sed -e 's/^ *Label: //' -e 's/^ *//' | sort -V | tail -n1) | |
# $label is like 'Command Line Tools for Xcode-16.0' | |
if [ -n "$label" ]; then | |
(set -x; softwareupdate -i "$label") | |
installed=1 | |
fi | |
rm -f "$tmp_file" | |
if [ "$installed" = "0" ]; then | |
(set -x; xcode-select --install) | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment