The fastest way to install Xcode on macOS—via the command line—requires only a terminal session and a few minutes. This method installs the latest Xcode version, including all developer tools, without manually downloading a disk image, and works on any Mac running macOS 10.15 (Catalina) or later. No GUI interaction is needed beyond opening Terminal.
What You'll Need
- A Mac running macOS Catalina (10.15) or later (Xcode 12+ is required for this method).
- An internet connection (deployment package downloads from Apple).
- Terminal (built into macOS; no additional software needed).
- A user account with administrative privileges to install software.
- No additional tools—Xcode is installed directly via the command line.
Step-by-Step
- Open Terminal
Press
Command+Space, typeTerminal, and hitEnter. No installation is required for the app—it’s included with macOS since Ventura. - Set up the Xcode Developer Account (if needed)
If you haven’t already:
- Visit developer.apple.com/account and sign in with your Apple ID.
- Go to Settings > Download Apps and enable Developer Tools (if prompted).
- In Terminal, run:
softwareupdate --install --agree-to-license --fetch-xcodeThis automatically downloads and installs the latest Xcode version (as of writing, this fetches Xcode 15 with macOS Sonoma compatibility). The first time you run this, macOS may ask for your password to verify the source.
- Verify Xcode Installation
After the download completes (typically takes 5–15 minutes), check installation:
- Run:
xcode-select --installThis opens the Xcode Installer app (if not already installed). Click Install to start. - Once installed, verify the version with:
xcodebuild -versionExpected output (example):Xcode 15.0Command line tools are already installedIf you see "Command line tools are not installed," run:xcode-select --installagain.
- Run:
- Set Xcode as Default Command Line Tool
Some developers prefer Xcode’s tools over the system’s (which may be outdated). Run:
sudo xcode-select -switch /Applications/Xcode.app/Contents/DeveloperEnter your admin password when prompted. This makes Xcode the active framework directory. - Launch Xcode (Optional)
To open the IDE directly:
open -n /Applications/Xcode.appThe app will launch with a welcome screen. Close it to avoid unnecessary CPU use.
Common Mistakes
- Slow or frozen Terminal
If the command hangs, check your internet connection or wait for the download to timeout. Retry with:
softwareupdate --fetch-xcode --forceAlternative: Manually download from: (Choose "Xcode" in the latest macOS version.) - Permission errors during installation
Add your user to the Administrators group via
sudo dscl . -append /Groups/admin GroupMembership username, then restart Terminal. If macOS blocks the download, use the GUI installer instead. - Xcode not installing after the first run
If the installer app fails silently, force-quit it (hold
Command+Q) and run:sudo xcode-select --resetThen re-runxcode-select --install. - MacOS too old (<10.15)
The command-line method requires Catalina or later. Upgrade if needed in
System Settings > Software Update.
Tips
- Skip the GUI if you need it now If you encounter a blocked download, manually download Xcode from Apple’s site (link above) and install via the GUI. This avoids potential macOS restrictions.
- Use the latest macOS version Xcode must be compatible with your macOS. Check compatibility here: If you’re on an older Mac (e.g., 2013 or earlier), consider upgrading hardware or using a newer macOS version.
- Organize Xcode tools
After setting Xcode as default with
xcode-select, use:xcode-select --showto verify the path. Adjust if needed (e.g., pointing to a mirrored Xcode on a shared drive). - Automate future installs
Save this as a script (e.g., in
~/bin/install_xcode.sh):#!/bin/bash softwareupdate --install --agree-to-license --fetch-xcode xcode-select --installMake it executable withchmod +x install_xcode.shand run via./install_xcode.sh. - Check for updates
After installation, verify updates with:
xcodebuild -listor run the GUI installer periodically for patches.
Troubleshooting
- Xcode fails to launch
If you see an error like "The command line tools are already installed but the version is too old," run:
sudo rm -rf /Library/Developer/CommandLineToolsthen reinstall via:xcode-select --install. Warning: This removes the legacy tools—ensure you’re not using them for critical builds. - MacOS blocks the download
The deployment package may be rejected by macOS due to signing. In this case:
- Open
System Settings > Privacy & Security. - Find the downloaded package in
~/Downloadsand click Open (not "Open with Xcode"). - Follow the installer prompts.
- Open
- Terminal shows "command not found"
Ensure Xcode is set as the active developer directory:
xcode-select --printIf it returns/Applications/Xcode.app/Contents/Developer, proceed. If not, run:sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer. - System Integrity Protection (SIP) errors
SIP may block Xcode installer files. As a last resort, boot into Recovery Mode (hold
Command+Rat startup), then:- Open Terminal.
- Run:
csrutil disablereboot - Reinstall Xcode after reboot.
- Re-enable SIP with:
csrutil enable(Remove this line after installation.)
Frequently Asked Questions
Why does Xcode install take so long?
- The command-line method downloads a full deployment package (~600MB) and installs the entire Xcode suite, including tools, libraries, and documentation. This is faster than manually downloading individual components but slower than the GUI installer.
Can I use this method on a Mac under macOS 10.15?
- No. The deployment package only works on macOS Catalina (10.15) or later. Older Macs require the GUI installer or an unsupported workaround (e.g., running Xcode on a newer Mac via Remote Desktop).
What if I get a "Developer account not enabled" error?
- Go to developer.apple.com/account/, sign in, and enable "Developer Tools" under Settings > Download Apps. Then retry the command.
Does this method work on M1/M2 Macs?
- Yes, but with a caveat: macOS Ventura (13.0+) and later support native ARM64 builds. If you see errors like "unrecognized architecture x86_64," ensure you’re using a macOS version that supports Xcode 15+ (Sonoma or later). For pre-Ventura M1/M2 Macs, use Xcode 14.x (compatible with Big Sur).
How do I uninstall Xcode after installation?
- Delete the Xcode.app bundle from
/Applicationsand remove the developer directory:sudo rm -rf /Library/Developer/CommandLineToolssudo rm -rf /Library/Developer/XcodeTo remove the entire package, use:sudo xcode-select --reset