A while back, I developed a script that will download and install the Xcode Command Line Tools on Macs running 10.7.x and higher.
Most of the time it works fine. However, starting with macOS Sierra and continuing on with macOS High Sierra, I occasionally ran into an odd problem. Apple would sometimes have both the latest available Xcode Command Line Tools installer and the just-previous version available on Apple’s Software Update feed.
The original script was written with the assumption that there would only be one qualifying Xcode Command Line Tools install option available at any one time. When more than one is available, the script isn’t able to correctly identify which Xcode Command Line Tools it should be installing. The result is that the script ends without installing anything.
Apple usually removes the previous version from the Software Update feed within a few days, which allows the script to work normally again. But when it happened this time, I decided to update the script to hopefully fix this issue once and for all. For more details, please see below the jump.
The fix was to add the following section to the script:
This section helps identify if Apple’s softwareupdate command line tool has returned more than one Xcode command line tool installation option. If more than one is available, the script will identify the last one listed and install that one.
Note: It is possible that a future release by Apple could result in the latest Xcode command line tool installer not being the one listed. This design decision was based on observation of past results.
The updated script is available below. It’s also available from my Github repo from the following link: