How To

Install Xcode Command Line Tools on macOS (Update, Remove)

Most developer tools on a Mac depend on Apple’s Xcode Command Line Tools. Homebrew will not install without them, git and make in /usr/bin are only stubs until they are present, and every Python wheel or Ruby gem that compiles C code needs the clang compiler they ship. You do not need the full Xcode app for any of that, and the command line tools package is a fraction of its size.

Original content from computingforgeeks.com - post 74963

This guide covers the lifecycle: installing the tools with xcode-select, installing them headless over SSH with softwareupdate, checking the version, updating after a macOS upgrade, fixing the invalid active developer path error and removing them cleanly. The output blocks come from a macOS 15.3.1 Mac running Command Line Tools 16.2, and every step was checked against Apple’s documentation and Homebrew’s installer in November 2026. We didn’t rerun the steps on a lab Mac for this update.

Decide between Xcode and the Command Line Tools

Pick the package by what you build, because the two install very different amounts of software. If you never open a project in Xcode, the standalone tools are enough, and they are what Homebrew, pyenv, rbenv and most language toolchains look for. The full Xcode app ships its own copy of the same compilers, so you only need both when you build apps for Apple platforms and also want a lighter path for scripts. The table sums up the split.

You needCommand Line ToolsFull Xcode
clang, make, git, ld, the macOS SDKYesYes
Homebrew, compiled Python/Ruby/Node modulesYesYes
iOS, watchOS and visionOS SDKs, simulatorsNoYes
Xcode IDE, Instruments, Interface BuilderNoYes
Install location/Library/Developer/CommandLineTools/Applications/Xcode.app
DownloadUnder 1 GBSeveral GB from the App Store

The Command Line Tools package is an under-1 GB download, while Xcode is a multi-gigabyte App Store download that then asks for extra components on first launch. When you install full Xcode later, open it once and accept that prompt, because it installs the platform pieces the IDE needs. The prompt looks like this.

Xcode first launch dialog asking to install additional required components

That dialog belongs to Xcode.app only. The standalone tools never show it, so if you only want a compiler and git, skip the App Store entirely and carry on with the next section.

Check whether the tools are already installed

Before installing anything, ask xcode-select which developer directory is active, since Homebrew or an earlier Xcode may have put the tools there already. A second install changes nothing, so it pays to look first.

xcode-select -p

On a Mac with only the standalone tools, it prints /Library/Developer/CommandLineTools. If full Xcode is selected instead, you get the path inside the app bundle, which is what the original capture for this guide showed:

/Applications/Xcode.app/Contents/Developer

A clean Mac answers with xcode-select: error: unable to get active developer directory instead. In that state, running git --version does not print a version. It prints xcode-select: note: No developer tools were found, requesting install. and pops the installer dialog, which is a perfectly good way to start the install too.

Install Xcode Command Line Tools with xcode-select

On a Mac you’re sitting in front of, the quickest route is the built-in installer. Open Terminal and run:

xcode-select --install

macOS answers with a dialog asking whether you want the command line developer tools now. Any stubbed tool triggers the same prompt with its own name in the title, so the title names whichever tool called it. Click Install, not Get Xcode, unless you want the multi-gigabyte IDE.

macOS dialog saying the xcrun command requires the command line developer tools, with Get Xcode, Not Now and Install buttons

Accept the licence agreement on the next screen and the download starts. Choosing Not Now only postpones it, because the dialog comes back the next time any stubbed tool runs. The progress window stays up while the package downloads and installs.

Command Line Tools installer window showing the Downloading software progress bar with a Stop button

We’d expect several minutes on a typical home connection, since the package runs to hundreds of megabytes. If you run xcode-select --install on a Mac that already has the tools, nothing downloads. You get xcode-select: note: Command line tools are already installed. and a pointer to Software Update. That is where updates come from, and the update section below shows the Terminal side of it.

Install headless with softwareupdate

The GUI dialog is useless over SSH, on a headless Mac mini or in a provisioning script. Homebrew’s own installer solves this with a placeholder file that makes softwareupdate list the Command Line Tools as an available update, and you can use the same trick by hand. Create the placeholder first:

sudo touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress

With that file present, list the available updates and look for an entry whose label starts with Command Line Tools for Xcode.

softwareupdate --list

Each entry has a Label line and a Title line with the version and size. A log posted from a macOS 26.3 machine shows the label as Command Line Tools for Xcode 26.3-26.3, and the exact label is what softwareupdate needs, so copy it verbatim or let the shell pick the newest one. We use the same parsing Homebrew’s installer runs, which keeps the newest label when several are listed.

CLT_LABEL=$(softwareupdate --list 2>/dev/null | grep -B 1 -E 'Command Line Tools' | awk -F'*' '/^ *\*/ {print $2}' | sed -e 's/^ *Label: //' -e 's/^ *//' | sort -V | tail -n1)
echo "$CLT_LABEL"

If echo prints an empty line, softwareupdate found no Command Line Tools entry, usually because the placeholder file is missing or Apple’s catalog has nothing for that macOS release yet. Once a label prints, install it and remove the placeholder so later softwareupdate runs behave normally.

sudo softwareupdate --install "$CLT_LABEL" --verbose
sudo rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress

Finally, point the active developer directory at the new tools. Homebrew does this step too, because a stale selection from an old Xcode would otherwise keep winning.

sudo xcode-select --switch /Library/Developer/CommandLineTools

When the catalog route fails completely (an air-gapped Mac, or a release Apple has pulled), download the .dmg instead. Sign in at Apple’s developer downloads page with any free Apple ID, search for “Command Line Tools”, and pick the build that matches your macOS version. For an air-gapped Mac, do the download on another machine and copy the .dmg across.

Verify the version and active path

xcode-select only tells you the path, not which release sits there. The installer leaves a package receipt, and its version string is the most reliable way to read the Command Line Tools version.

pkgutil --pkg-info=com.apple.pkg.CLTools_Executables

The first numbers of version are the release (16.2 here), and install-time is a Unix timestamp you can feed to date -r to see when it was installed:

package-id: com.apple.pkg.CLTools_Executables
version: 16.2.0.0.1.1733547573
volume: /
location: /
install-time: 1734862802

The xcode-select binary carries its own build number, which is handy when you are comparing two Macs for a support ticket.

xcode-select --version

It prints one line with the build. Another macOS release may print a different build, which is fine:

xcode-select version 2409.

If Homebrew is installed, brew config reports the tools from Homebrew’s side, and it is the output Homebrew maintainers ask for in bug reports. The CLT, Xcode and Clang lines near the end are the ones that matter here.

brew config

On the test Mac both packages were present, so Homebrew lists CLT 16.2 and Xcode 15.4 side by side:

HOMEBREW_VERSION: 4.4.23
ORIGIN: https://github.com/Homebrew/brew
HEAD: 64efed206deeb9c2304d9e5b5910dcbf0a509c15
Last commit: 9 days ago
Branch: stable
Core tap JSON: 10 Mar 12:07 UTC
Core cask tap JSON: 10 Mar 12:07 UTC
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 3.3.7 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/3.3.7/bin/ruby
CPU: octa-core 64-bit icelake
Clang: 15.0.0 build 1500
Git: 2.46.0 => /usr/local/bin/git
Curl: 8.7.1 => /usr/bin/curl
macOS: 15.3.1-x86_64
CLT: 16.2.0.0.1.1733547573
Xcode: 15.4

That capture shows a mismatch worth spotting on your own machine. The CLT is a newer release than Xcode, and the Clang version comes from whichever one xcode-select points at. If a build complains about an SDK or compiler version you did not expect, check the active path before reinstalling anything. The /usr/local prefix also tells you it is an Intel Mac, since Apple silicon installs use /opt/homebrew.

Update the Command Line Tools

Updates come through Software Update, not xcode-select. New releases show up in System Settings > General > Software Update next to macOS updates, so it is easy to install one by accident or skip it for months. From Terminal, list what is pending.

softwareupdate --list

If a Command Line Tools for Xcode entry appears, install it by its exact label. Quote it, because labels contain spaces.

sudo softwareupdate --install "Command Line Tools for Xcode 26.3-26.3"

Replace the label with the one your Mac prints. Software Update only lists releases compatible with your macOS, so no entry usually means you are already current for that release. If you still want a fresh copy, reuse the placeholder trick from the headless section, or remove the old tools and install fresh, which takes about as long and leaves no half-updated directory behind.

Plan an update after every major macOS upgrade, because upgrades are the usual moment the tools break. On Macs moving to macOS 27 Golden Gate, check the developer toolchain first. The other changes are listed in our macOS Golden Gate notes for developers.

Fix “xcrun: error: invalid active developer path”

This is the error most people search for, and it nearly always shows up right after a macOS upgrade, the first time you run a build tool or brew.

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

The path in the message is still selected, but the files behind it are gone or incomplete, because the upgrade replaced part of /Library/Developer/CommandLineTools and left the rest. Reinstalling is the fix, so try the normal installer first.

xcode-select --install

If it refuses with “Command line tools are already installed” while xcrun is clearly missing, the leftover directory is fooling it. Delete the directory, then run the installer again.

sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install

When full Xcode is installed and you would rather use it, skip the reinstall and select the app instead with sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer, covered in the next section. Either way, confirm with xcrun --find clang, which prints a path inside the selected directory once the toolchain is whole again.

Switch between Xcode and the Command Line Tools

With both packages installed, only one is active at a time, and the choice is system-wide. Three commands cover every case:

  • sudo xcode-select --switch /Library/Developer/CommandLineTools for the standalone tools
  • sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer for full Xcode
  • sudo xcode-select --reset to clear the choice and let macOS pick the default

Because --switch changes the path for every user, a CI runner that needs a different Xcode for one job should export DEVELOPER_DIR for that shell instead. It overrides the system selection for the current session only.

export DEVELOPER_DIR=/Library/Developer/CommandLineTools
xcrun --find clang

The xcrun lookup should resolve inside the directory you exported. Unset the variable or open a new shell to go back to the system choice. Nothing on disk changes, so other users and jobs keep their selection.

Uninstall the Command Line Tools

Apple has no uninstaller for the standalone tools. Its command line tools documentation (and the older TN2339 note before it) says to remove the /Library/Developer/CommandLineTools directory, which takes the files off the disk.

sudo rm -rf /Library/Developer/CommandLineTools

The developer commands then go back to being stubs that prompt for an install. xcode-select -p may still print the deleted path, because the selection is stored separately from the files, so run sudo xcode-select --reset to clear it. If Xcode.app is still installed, the reset also makes tools resolve to it rather than to the deleted directory.

Package receipts in the pkgutil database survive the delete. Apple notes that Software Update keeps offering Command Line Tools updates while the com.apple.dt.commandlinetools receipt remains, and the version check from earlier can still report a release that is no longer on disk. List every related receipt first.

pkgutil --pkgs | grep -i -e CLTools -e commandlinetools

Forget the one Apple names so the update offers stop, then the executables receipt behind the version check:

sudo pkgutil --forget com.apple.dt.commandlinetools
sudo pkgutil --forget com.apple.pkg.CLTools_Executables

Repeat --forget for any other receipt the list printed. Think twice before uninstalling on a machine that uses Homebrew, though, because several things you probably rely on stop working the moment the directory goes:

  • Homebrew formulae that build from source
  • the git that brew update runs
  • pip, gem and npm packages with C extensions

Homebrew’s install script also puts the tools back on its next run, so removing them on a Homebrew Mac is only worth it as the first half of a clean reinstall.

Keep the toolchain healthy

For nearly every developer Mac, our pick is the standalone Command Line Tools installed with xcode-select --install. Add full Xcode only when you ship for Apple platforms. Check xcode-select -p and the pkgutil version after each macOS upgrade, and you’ll catch the xcrun error before a build does. With the toolchain in place, the next steps are usually a better shell with Zsh and Oh My Zsh on macOS (our comparison of Linux and macOS shells covers the alternatives), a quieter Homebrew by disabling its auto update, the brew cask syntax fix if old scripts fail, and the ip and ifconfig commands on macOS for network work.

Keep reading

macOS Keyboard Shortcuts Cheat Sheet (Golden Gate and Tahoe) Cheat Sheets macOS Keyboard Shortcuts Cheat Sheet (Golden Gate and Tahoe) Install GitHub CLI (gh) on Linux, macOS, and Windows Programming Install GitHub CLI (gh) on Linux, macOS, and Windows Fix β€œapt-key is deprecated. Manage keyring files in trusted.gpg.d instead” Debian Fix β€œapt-key is deprecated. Manage keyring files in trusted.gpg.d instead” How To Install Python 3.13 on Ubuntu 24.04|22.04 Programming How To Install Python 3.13 on Ubuntu 24.04|22.04 Install Python 3.11 on Ubuntu 26.04 / 24.04 / 22.04 Programming Install Python 3.11 on Ubuntu 26.04 / 24.04 / 22.04 Manage Angular Projects with Angular CLI (Guide) Programming Manage Angular Projects with Angular CLI (Guide)

Leave a Comment

Press ESC to close