Quick Summary: The error
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrunoccurs on macOS when Apple’s Command Line Tools (CLT) are missing, corrupted, or pointing to an outdated path. This most commonly happens immediately after a macOS system upgrade, after uninstalling the full Xcode application, or when an OS update clears the developer directory without reinstalling the tools.
Understanding the Root Causes
On macOS, system shims in /usr/bin/ (including git, python3, make, clang, and gcc) do not contain the actual binaries; instead, they delegate execution through xcrun to whichever active developer directory is configured by xcode-select. Execution fails when:
- macOS System Updates: Major or minor macOS updates frequently invalidate or remove
/Library/Developer/CommandLineTools, requiring a fresh reinstall to match the new OS SDK headers. - Uninstalling Full Xcode.app: If
xcode-selectpreviously pointed to/Applications/Xcode.app/Contents/Developerand Xcode was moved to the Trash, all developer shims break until the active path is reset. - Unaccepted License Agreement or Corrupted Path: An incomplete CLT update or stale
DEVELOPER_DIRenvironment variable pointing to a non-existent directory.
Step 1: Quick Fix – Reinstall Xcode Command Line Tools
Trigger the native macOS Command Line Tools installer directly from Terminal:
# 1. Launch the official macOS Command Line Tools installer GUI
xcode-select --install
# 2. Click "Install" in the popup dialog and agree to the license terms.
# Wait for the download and installation to complete (typically 2-5 minutes).
# 3. Verify the active developer path after installation
xcode-select -p
# Expected output: /Library/Developer/CommandLineTools
Step 2: Reset or Switch the Active Developer Directory
If xcode-select --install reports that the tools are already installed (or if you uninstalled Xcode.app), reset the active path or point it explicitly to an existing installation:
# Option A: Reset xcode-select to the default Command Line Tools path
sudo xcode-select --reset
# Option B: Explicitly select the Command Line Tools directory
sudo xcode-select --switch /Library/Developer/CommandLineTools
# Option C: Point to full Xcode.app if you have it installed in /Applications
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
# Check if a stale DEVELOPER_DIR environment variable is overriding xcode-select
echo "$DEVELOPER_DIR"
unset DEVELOPER_DIR
Step 3: Perform a Clean Reinstall (If Installer Fails or Loops)
If the GUI installer fails or xcrun remains missing despite running xcode-select --reset, remove the corrupted directory and reinstall cleanly via Software Update:
# 1. Remove the broken Command Line Tools directory
sudo rm -rf /Library/Developer/CommandLineTools
# 2. Trigger a fresh installation prompt
xcode-select --install
# Alternative headless install via softwareupdate (useful over SSH):
touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
PROD=$(softwareupdate -l | grep "\*.*Command Line" | tail -n 1 | sed 's/^[^C]* //')
softwareupdate -i "$PROD" --verbose
rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
Verification & Testing Steps
Confirm that xcode-select resolves cleanly and that standard developer shims execute without errors:
# 1. Verify the active developer path
xcode-select -p
# 2. Confirm xcrun and clang binaries respond normally
xcrun --find git
clang --version
# 3. Inspect installed CLT package metadata
pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
Troubleshooting Summary Comparison
| Scenario | Primary Root Cause | Recommended Solution |
|---|---|---|
| Error appears after macOS OS update | OS upgrade cleared /Library/Developer/CommandLineTools |
Run xcode-select --install |
| Error appears after deleting Xcode.app | xcode-select still points to deleted /Applications/Xcode.app |
Run sudo xcode-select --reset |
| Tools installed, error persists | Corrupted CLT folder or stale DEVELOPER_DIR env var |
Remove /Library/Developer/CommandLineTools and reinstall |
| Headless Mac / SSH session | Cannot click GUI installation prompt | Install via softwareupdate -i using the CLT placeholder file |
Leave a Reply