Install Xcode Command Line Tools with Homebrew
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.
The easiest way to install Xcode Command Line Tools is by installing Homebrew, the popular package manager for macOS. With Homebrew, you can install almost any open source developer tool. Since you'll probably need Homebrew in your local development environment, you might as well let Homebrew install Xcode Command Line Tools for you. This is a recent addition to the Homebrew installation process, so older guides or blog posts won't mention it.
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.
Steps
Here are steps to install Xcode Command Line Tools using Homebrew.
- Check macOS and update macOS.
- Check if Xcode Command Line Tools was previously installed.
- Install Homebrew (with an option to install Xcode Command Line Tools).
- Update the shell configuration (Mac M1, M2, M3 only).
These instructions are for a terminal running Zsh, the Z shell, on a newer Mac. Older Macs may be running the Bash shell and you should upgrade. See Shell Configuration.
Tip: If you did not use a password to log in to your Mac (that is, if your password is blank), you cannot install Homebrew.
Check for Homebrew
If you've already checked macOS and checked if Xcode Command Line Tools was previously installed, then check if Homebrew is installed:
$ brew
If Homebrew is not installed, you will see:
zsh: command not found: brew
If Homebrew is not installed, there should be no Homebrew files in /usr/local
(for macOS Intel) or /opt/homebrew
(for Apple Silicon). If you think Homebrew is already installed, see Zsh: command not found: brew for details. You may need to Uninstall Homebrew.
Brew install
Homebrew provides an installation script you can download and run with a single command (check that it hasn't changed at the Homebrew site). This is the easiest way to install Homebrew.
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
The Homebrew installation script will ask you to enter your Mac user password. This is the password you used to sign into your Mac.
Password:
You won't see the characters as you type. Press enter when you are done.
You'll see a list of files and folders that Homebrew will install.
Option to install XCode Command Line Tools
If you haven't already installed XCode Command Line Tools, you'll see a message that "The XCode Command Line Tools will be installed." Press return to continue when prompted by the Homebrew installation script. It only takes a minute or two to download and install the Command Line Tools on a 2021 Mac M1 Mini.
You’ll see diagnostic and progress messages. Full Homebrew installation takes 2 to 15 minutes on a 2021 Mac M1 Mini, with a 100Mbps Internet connection. It's significantly slower on Mac Intel over a slow Internet connection.
On Mac Intel machines, that's all you need to do; Homebrew is ready to use. On Mac Intel, Homebrew installs itself into the /usr/local/bin
directory, which is already configured for access by the shell with the macOS default $PATH
environment variable (the default is set by the /usr/libexec/path_helper
command).
Homebrew checks the shell configuration
On Apple Silicon machines, there's one more step. Homebrew files are installed into the /opt/homebrew
folder. But the folder is not part of the default $PATH
.
$PATH
is a shell environment variable that shows where executable programs are located. When you run a command in the terminal, the shell searches through the directories listed in your $PATH
variable to find the executable file for that command. With a correct $PATH
, you don't need to type the full path to a program every time you want to run it.
The Homebrew install script will check if you've previously set a $PATH
that includes the Homebrew folders (this is likely if you installed Homebrew previously).
Add to the $PATH shell configuration (first time users)
If you're a first time Homebrew user, Homebrew will display instructions to set the $PATH
environment variable, as well as other Homebrew-related environment variables.
Homebrew shows instructions at the end of the installation process. Follow Homebrew's advice and set up a ~/.zprofile
file which contains a command which sets up Homebrew:
==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
The example above contains the Unix ~
tilde shortcut. The Homebrew console output will show your user directory name instead.
Be very careful to copy the commands exactly. It's best to copy and paste. If you enter the commands manually and you enter a single >
instead of the double >>
you will replace the .zprofile
instead of appending.
The shell eval
command executes the commands in the shellenv
file found in the /opt/homebrew/bin/brew
folder.
See Shell Configuration and setting the Mac Path for background and details.
Verify Homebrew installation
After you've installed Homebrew, check that Homebrew is installed properly.
$ brew doctor
You should see:
Your system is ready to brew.
On Apple Silicon, if you see zsh: command not found: brew
, check that you've created a ~/.zprofile
file as described above and restart your terminal application.
If Homebrew is successfully installed, there will be Homebrew files in /usr/local
(for macOS Intel) or /opt/homebrew
(for Apple Silicon).
What's next
Now you have both Xcode Command Line Tools and Homebrew installed. If you want to learn more about adding Homebrew packages to set up your development environment, see Install a Homebrew Package.
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.