Install Xcode Command Line Tools on a Headless Mac.

Install Apple’s Xcode Command Line Tools on a headless Mac over SSH. Download the compatible package, copy it from a GUI Mac, install it from Terminal, and verify the active developer directory.

Install Xcode Command Line Tools on a Headless Mac.
Image credit: Unknown. Please contact us if you are the owner.

A routine maintenance check can turn into hours of troubleshooting when a remote Mac needs an update that expects a graphical prompt. I recently found an older version of Apple’s Xcode Command Line Tools on a build server. Running xcode-select --install over SSH did not complete the installation because the confirmation dialog could not be handled remotely.

The reliable workaround was to download Apple’s installer on a Mac with a graphical session, copy the package to the server, and install it over SSH. This guide walks through that process.

What you need

  • A Mac with a GUI session to download and inspect Apple’s installer image.
  • SSH access to the headless Mac.
  • Administrator privileges on the headless Mac.
  • A Command Line Tools package compatible with the target Mac’s macOS version and hardware.

Apple distributes Command Line Tools for Xcode through its developer downloads as a disk image (.dmg). The image contains a macOS installer package (.pkg). You can mount the image on the GUI Mac, transfer the package, and run Apple’s installer command on the remote Mac.

Compatibility matters: Check Apple’s Xcode releases information and choose a Command Line Tools version supported by the target macOS release. Apple installs the tools in /Library/Developer/CommandLineTools, and only one standalone Command Line Tools package can be installed at a time.


Step 1: Download the Command Line Tools disk image

On the Mac with a GUI session, visit Apple Developer Downloads and sign in with your Apple ID. Search for Command Line Tools for Xcode and download the package appropriate for the target Mac’s macOS version.

The filename changes between releases. In the commands below, replace Command_Line_Tools_for_Xcode.dmg with the actual downloaded filename.

Step 2: Mount the DMG and locate the installer package

In Terminal on the GUI Mac, attach the disk image:

$ hdiutil attach "$HOME/Downloads/Command_Line_Tools_for_Xcode.dmg"

hdiutil is a command-line disk-image utility; mounting a DMG does not require Finder or a graphical session. The command should print the mounted volume path, often something like /Volumes/Command Line Tools or /Volumes/Command Line Developer Tools.

List the mounted volume’s contents. Use the exact path printed by hdiutil if it differs from this example:

$ ls "/Volumes/Command Line Tools"

Look for the .pkg installer, commonly named Command Line Tools.pkg.

Step 3: Copy the PKG to the headless Mac

Use scp from the GUI Mac to copy the installer to a temporary directory on the remote Mac. Replace user and headless-mac with your SSH username and host, and adjust the volume path if needed:

$ scp "/Volumes/Command Line Tools/Command Line Tools.pkg" user@headless-mac:/tmp/

Enter your SSH password if prompted, or use your configured SSH key. The package should now be at /tmp/Command Line Tools.pkg on the headless Mac.

Step 4: Eject the mounted disk image

After the transfer finishes, detach the volume on the GUI Mac:

$ hdiutil detach "/Volumes/Command Line Tools"

This cleanly unmounts the image. If the volume path differs, use the path reported when you attached the DMG.

Step 5: Install the package over SSH

Connect to the headless Mac:

$ ssh user@headless-mac

Run the macOS installer against the package copied to /tmp:

$ sudo installer -pkg "/tmp/Command Line Tools.pkg" -target /

Enter the administrator password when prompted. The installer places the standalone Command Line Tools package at /Library/Developer/CommandLineTools.

Step 6: Select the Command Line Tools developer directory

Set the active developer directory to the standalone tools installation:

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

This makes Apple’s command-line developer tools the active toolchain. If the Mac uses a full Xcode installation instead, its developer directory is typically inside the Xcode application bundle; do not switch to the Command Line Tools path unless that package is installed.

Step 7: Verify the installation

Confirm the active developer directory:

$ xcode-select -p

For this setup, the expected output is:

/Library/Developer/CommandLineTools

Check the installed package receipt and key tools:

$ pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
$ clang --version
$ make --version
$ git --version

The pkgutil output includes the installed package version. The tools should report version information without prompting to install developer tools. Note that xcodebuild and xctrace are part of full Xcode and are not included in the standalone Command Line Tools package.



Troubleshooting

The installer reports the package is incompatible

Download a Command Line Tools release compatible with the target Mac’s macOS version. Apple’s release notes list compatibility details; a package built for a newer macOS may not install on an older system.

xcode-select -p points to the wrong location

Run the xcode-select --switch command again with the path to the installed developer directory. To inspect the currently selected path without changing it, run xcode-select -p.

xcode-select --install still asks for a GUI prompt

That command opens a system dialog to request installation. On a headless Mac, use Apple’s downloadable installer package and the installer workflow described above.

Some expected Xcode commands are missing

The standalone Command Line Tools package does not include every command shipped with the full Xcode application. In particular, xcodebuild and xctrace require Xcode. Install and select full Xcode if your build workflow depends on those tools.

A headless Mac does not need Finder to install Apple’s Command Line Tools. Download the compatible installer image on a GUI Mac, mount it with hdiutil, copy the package over SSH, and install it with macOS’s installer command. Selecting the developer directory and checking the package receipt confirms that the server is using the expected toolchain.

Keep Us Caffeinated  ⦿ ⦿
Spotify Logo
↑
SNUBmonkey Join our readers