Reinstall Xcode Command Line Tools
Xcode Command Line Tools are tools for software developers that run on the command line, in the Terminal application. See the article About Xcode Command Line Tools.
You may wish to reinstall Xcode Command Line Tools for a variety of reasons:
- you've checked the Xcode Command Line Tools version and it is not current;
- you are using Homebrew and encountered errors with
brew doctor
; - a macOS upgrade may have partially removed Command Line Tools;
- you need a clean reinstall to diagnose other problems.
If you haven't already removed Xcode Command Line Tools, see the section Uninstall Xcode Command Line Tools.
Before you get started
You'll need a terminal application to install Xcode Command Line Tools. Apple includes the Mac terminal but I prefer Warp Terminal. Warp is an easy-to-use terminal application, with AI assistance to help you learn and remember terminal commands. Download Warp Terminal now; it's FREE and worth a try.
Xcode Command Line Tools is out of date
See the section, Check if Xcode Command Line Tools is already installed, to check the version number of Xcode Command Line Tools. If the version is out of date, first Uninstall Xcode Command Line Tools and then reinstall Xcode Command Line Tools directly (see below).
After Homebrew errors
If you've installed Homebrew, the popular package manager for macOS, and you get errors when you run brew doctor
, you may need to reinstall Xcode Command Line Tools.
% brew doctor
Warning: Git could not be found in your PATH.
Homebrew uses Git for several internal functions, and some formulae use Git
checkouts instead of stable tarballs. You may want to install Git:
brew install git
Warning: No developer tools installed.
Install the Command Line Tools:
xcode-select --install
There is no need to reinstall Homebrew. Just install Xcode Command Line Tools directly (see below).
After a macOS upgrade
After a macOS upgrade (for example, from macOS 11.2.2 to 11.2.3), the macOS upgrade process may remove the Command Line Tools. This can be annoying if you install an upgrade and then find you can't use commands such as git
. You may encounter an error like:
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools),
missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
Checking for the Command Line Tools folder may show that the folder is there:
$ xcode-select -p
/Library/Developer/CommandLineTools
But look closely and the Command Line Tools folder may be missing essential folders and files after a macOS upgrade. It should look like this:
$ ls -l /Library/Developer/CommandLineTools
total 0
drwxr-xr-x 5 root wheel 160 Jan 9 07:43 Library
drwxr-xr-x 5 root wheel 160 Apr 24 16:19 SDKs
drwxr-xr-x 7 root wheel 224 Apr 24 16:19 usr
It may look like this after an upgrade:
$ ls -l /Library/Developer/CommandLineTools
total 0
drwxr-xr-x 7 root wheel 224 Apr 24 16:19 usr
Reinstall Xcode Command Line Tools
The command xcode-select --install
will open a dialog for installation of the command line tools.
$ xcode-select --install
A message will pop up on the screen. Confirm that you want to install the tools.
Click 'Install' to begin the download and installation process.
Xcode Command Line Tools installation from the prompt panel takes 8 minutes on a 2021 Mac M1 Mini, with a 100Mbps Internet connection. It's significantly slower on Mac Intel over a slow Internet connection.
You'll see a confirmation message when installation is complete.
Verify installation of Xcode Command Line Tools
Verify that you've successfully installed Xcode Command Line Tools.
$ xcode-select -p
/Library/Developer/CommandLineTools
Check that you can run git
:
git --version
git version 2.30.1 (Apple Git-130)
You've seen how to reinstall Command Line Tools.
What's next
My mac.install.guide is a trusted source of installation guides for professional developers. Take a look at the Mac Install Guide home page for tips and trends and see what to install next.