Xcode stops working after set xcode-select -switch
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
The xcode-select command-line utility on macOS controls which developer tools directory the system uses for compiling code, running git, and other development tasks. Running xcode-select --switch (or its short form -s) to point to a different toolchain can unexpectedly break Xcode itself, leaving you with build failures, missing SDKs, or an IDE that refuses to launch. This article explains why this happens and how to recover.
What xcode-select Does
Every macOS developer tool -- from clang to git to swift -- looks up its active toolchain by querying the "developer directory" path managed by xcode-select. You can see the current path with:
When you run xcode-select --switch, you change this path system-wide. Every tool that depends on it immediately starts using the new location.
Why Xcode Breaks After Switching
Pointing to Command Line Tools Instead of Xcode
The most common cause of breakage is switching to /Library/Developer/CommandLineTools. The standalone Command Line Tools package contains compilers and headers but does not include iOS/watchOS/tvOS SDKs, Interface Builder, the Simulator runtime, or the full Xcode build system. When Xcode launches, it expects the developer directory to point to its own Contents/Developer folder. If it finds the Command Line Tools path instead, features break or the app cannot start.
Pointing to a Nonexistent or Moved Path
If you previously switched to an Xcode beta and then deleted or moved that beta, the developer directory points to a path that no longer exists. Every tool call fails with a "no developer tools found" error.
Version Mismatch
Switching between significantly different Xcode versions (for example, from Xcode 15 to Xcode 14) can cause incompatibilities. Build settings, Swift compiler versions, and SDK headers differ between major releases, leading to confusing build errors.
How to Fix It
Reset to the Default Xcode Installation
The quickest recovery is to point back to your main Xcode installation:
If you have renamed Xcode or installed it in a non-standard location, adjust the path accordingly. You can verify it worked:
Use xcode-select --reset
If you are unsure which path is correct, the --reset flag reverts to the default behavior where the system automatically finds Xcode:
After resetting, the system uses the default search order to locate Xcode. This is the safest option when you have a standard Xcode installation in /Applications.
Reinstall Command Line Tools
If switching corrupted your Command Line Tools installation or you are seeing errors about missing headers, reinstall them:
This opens a dialog prompting you to download and install the latest Command Line Tools package. After installation completes, make sure the developer directory still points to Xcode (not the Command Line Tools) if you need the full IDE.
Use DEVELOPER_DIR for Temporary Switches
Instead of changing the system-wide path, you can set the DEVELOPER_DIR environment variable for a single command or shell session. This avoids affecting Xcode or other tools.
This is the recommended approach when you need to test against a beta Xcode without disrupting your main development environment.
Verifying Your Setup
After making changes, run these checks to confirm everything is working:
If any of these fail, the developer directory is still pointing to the wrong location.
Common Pitfalls
- Forgetting
sudo:xcode-select --switchrequires root privileges. Withoutsudo, the command silently fails or prints a permission error, and the path remains unchanged. - Switching to
/Library/Developer/CommandLineToolsfor iOS development: The standalone CLT package has no iOS SDK. Always point to the full Xcode app bundle for iOS, watchOS, or tvOS work. - Not verifying the path after switching: Always run
xcode-select --print-pathafter a switch to confirm the change took effect and the path exists. - Using
--switchwhenDEVELOPER_DIRwould suffice: For temporary or per-project toolchain changes,DEVELOPER_DIRis safer because it does not affect the rest of the system. - Deleting an Xcode version without resetting the path: If you remove an Xcode beta or alternate installation, run
sudo xcode-select --switchor--resetfirst, otherwise every developer tool on the system breaks.
Summary
xcode-select --switchchanges the system-wide developer tools path, affecting Xcode, compilers, and all command-line tools simultaneously.- Xcode breaks most often when the path is set to
/Library/Developer/CommandLineTools(missing SDKs) or to a deleted Xcode installation (missing path). - Fix it with
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developerorsudo xcode-select --reset. - For temporary toolchain changes, prefer the
DEVELOPER_DIRenvironment variable over a system-wide switch. - Always verify your setup with
xcode-select --print-pathandxcrun --find clangafter making changes.

