Find, Install, or Uninstall XCode CLI
xcode-cli.Rd
Set of functions that seek to identify whether XCode CLI was installed, allow XCode CLI to be installed, and removing XCode CLI.
Usage
is_xcode_cli_installed()
xcode_cli_install(password = getOption("macrtools.password"), verbose = TRUE)
xcode_cli_uninstall(password = getOption("macrtools.password"), verbose = TRUE)
xcode_cli_path()
xcode_cli_switch(password = getOption("macrtools.password"), verbose = TRUE)
xcode_cli_reset(password = getOption("macrtools.password"), verbose = TRUE)
Check if XCode CLI is installed
Checks to see if Xcode CLI returns a viable path to the default Xcode CLI location by checking the output of:
XCode CLI Installation
The xcode_cli_install()
function performs a headless or non-interactive
installation of the Xcode CLI tools. This installation process requires
three steps:
Place a temporary file indicating the need to download Xcode CLI
Determine the latest version of Xcode CLI by running
softwareupdate
Install the latest version using
softwareupdate
withsudo
.
The alternative approach would be an interactive installation of Xcode CLI by typing into Terminal:
This command will trigger a pop up window that will walk through the package installation.
Steps of the Headless CLI Installation
The temporary file is created using:
From there, we deduce the latest version of Xcode available to the user through an R sanitized version of the chained shell commands:
product_information=softwareupdate -l |
grep '\\*.*Command Line' |
tail -n 1 |
awk -F"*" '{print $2}' |
sed -e 's/^ *//' |
sed 's/Label: //g' |
tr -d '\n'
Then, we trigger the installation process with sudo
using:
where $product_information
is obtained from the previous command.
Finally, we remove the temporary installation file.
These steps were obtained from Timothy Sutton's xcode-cli-tools.sh script and, slightly modernized.
Uninstalling Xcode CLI
The xcode_cli_uninstall()
attempts to remove only the Xcode CLI tools.
Per the Apple Technical Note TN2339:
Xcode includes all of the command-line tools. If it is installed on your system, remove it to uninstall the command-line tools.
If the
/Library/Developer/CommandLineTools
directory exists on your system, remove it to uninstall the command-line tools
Thus, the xcode_cli_uninstall()
opts to perform the second step only.
We use an R sanitized shell version of:
If the Xcode application is detect, we note that we did not uninstall the Xcode application. Instead, we request the user uninstall the Xcode app using the following steps:
Make sure that Xcode is closed. Quit Xcode if needed.
Open Finder > Applications, select Xcode and move it to Trash.
Empty the trash.
In addition, open Terminal and run:
Change Xcode CLI Location
If the Xcode Application has been previously installed, the underlying
path reported by xcode-select
may not reflect the Xcode CLI location.
The situation can be rectified by using the xcode_cli_switch()
function,
which changes the command line tool directory away from the Xcode application
location to the Xcode CLI location. This uses the default Xcode CLI
path.
If this does not fix the issue, we recommend using the xcode_cli_reset()
function.