How to Install Xcode With or Without Homebrew on a Mac


A lot of people search for brew install xcode or some other variation of how to install Xcode on a Mac, whether manually or with Homebrew. If you’re wondering the same thing, the first question you need to ask yourself is this:

Are you trying to develop an iOS app, or a macOS app, or any other project that requires the Xcode app?

If the answer is “no”, then you don’t need Xcode. What you want are the standalone Apple command line tools, which get automatically installed by Homebrew the first time you install it.

If the answer is “yes”, then the easiest way to install Xcode is from the Apple App Store. You can also install it with Homebrew using the mas command line tool, which allows you to install apps from the App Store directly from the Terminal.

Keep on reading for more details about each scenario.

How to install the command line tools on a Mac

To check if you already have Homebrew installed, run this command in your Terminal:

brew config

If it says brew: command not found, then you don’t have Homebrew, and you can install it with this command:

/bin/bash -c "$(curl -fsSL"

Homebrew will automatically download and install the command line tools as part of the Homebrew installation.

If brew config prints out a bunch of information, then you have Homebrew, and you can also check to see whether you have Xcode and/or the standalone command line tools by looking at the lines that start with Xcode: and CLT:

To check if Homebrew is properly set up, first make sure it’s up to date with brew update, then run brew doctor. If it prints out warnings or errors other than brew: command not found, then you have Homebrew, but something is wrong with it. If the warnings or errors mention the command line tools, follow the instructions to fix it.

Here are common errors about missing or outdated command line tools:

Warning: A newer Command Line Tools release is available.
Update them from Software Update in System Preferences or run:
  softwareupdate --all --install --force

If that doesn't show you any updates, run:
  sudo rm -rf /Library/Developer/CommandLineTools
  sudo xcode-select --install

Alternatively, manually download them from:

Here are other variations of the outdated message:

Warning: Your Command Line Tools are too outdated.
Warning: Your Command Line Tools (CLT) does not support macOS 11.
It is either outdated or was modified.
Please update your Command Line Tools (CLT) or delete it if no updates are available.

The missing tools message looks like this:

Warning: No developer tools installed.
Install the Command Line Tools:
  xcode-select --install

Homebrew usually provides detailed instructions for fixing things, so read them carefully and follow their instructions. Quit and restart Terminal once the command line tools are installed.

If you’re getting other Homebrew errors that you can’t figure out on your own, I wrote a script called Ruby on Mac that can automatically fix them in 1 minute!

How to install Xcode with Homebrew

Homebrew is a popular tool for Mac that makes it easy to install pretty much any development package. The other great thing about Homebrew is that you can also install Mac apps directly from the Terminal with Homebrew Cask, and with mas-cli to install App Store apps.

First, you need Homebrew. If you’re not sure if you have it or not, read the section above. Once you have Homebrew, you can install mas-cli:

brew install mas

Once mas is installed, you can search for apps like Xcode in the App Store:

mas search xcode

This might take some time since there are a lot of apps with “xcode” in the name or description. What you want is the first one that only says Xcode. Copy the id, which is 497799835, then install it using the id:

mas install 497799835

If, like me, you have a lot of Mac apps that you want to easily install and upgrade, you can define them all, along with Homebrew formulas, in a file called Brewfile. Here’s an example:

brew 'fish'
brew 'httpie'
brew 'mas'

cask 'alfred'
cask 'keyboard-maestro'
cask 'obsidian'

mas '1Password', id: 1333542190
mas 'Bear', id: 1091189122
mas 'Slack', id: 803453959

You can then install everything in that Brewfile like this:

brew bundle

This assumes the Brewfile is in the same directory as the one you’re running brew bundle from. Otherwise, you can specify the file location like this:

brew bundle --file="~/Brewfile"

Every time you run brew bundle, it will go through each tool or app, and install it if it isn’t already, or upgrade it if there’s a new version. Having everything defined in one file makes it easier to keep your dev setup and Mac apps up to date. It also comes in very handy when setting up a new computer. Check out my in-depth guide about how to automate the setup of a new Mac.