Update MacOs to Sonoma - Cannot Run Git: xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
The error you're seeing typically occurs after a macOS update when the Command Line Tools for Xcode are either missing or outdated. Here's how you can resolve it:
Solution: Reinstall Command Line Tools
-
Open Terminal: You can do this by searching for "Terminal" in Spotlight (press
Cmd + Space
and type "Terminal"). -
Install Command Line Tools: Run the following command to reinstall the Command Line Tools:
xcode-select --install
- This command will prompt you to install the necessary tools. Follow the on-screen instructions.
-
Check the Installation: After the installation completes, verify it by running:
xcode-select -p
- This should return a valid path like
/Library/Developer/CommandLineTools
.
- This should return a valid path like
-
Test Git: Try running a Git command, such as
git --version
, to confirm that Git is working correctly.
If the above steps don't resolve the issue, you may need to accept the Xcode license:
sudo xcodebuild -license
After accepting the license, test Git again. This should resolve the problem.
If sudo xcodebuild -license gives error
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
It seems that the system is recognizing the Command Line Tools but expects a full Xcode installation to proceed with the xcodebuild -license
command. Here's how you can handle this:
Option 1: Install Xcode
-
Install Xcode from the App Store:
- Open the App Store and search for Xcode. Download and install it.
-
Set the Active Developer Directory to Xcode:
-
After installing Xcode, you might need to set the active developer directory to Xcode:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
-
-
Accept the License:
-
Run the license command again:
sudo xcodebuild -license
-
Option 2: Reinstall Command Line Tools (If you don't want full Xcode)
If you prefer not to install the full Xcode, try the following:
-
Reset Command Line Tools Path:
-
Run the following command to reset the path:
sudo xcode-select --reset
-
-
Reinstall Command Line Tools:
-
Reinstall the Command Line Tools:
xcode-select --install
-
-
Test Git:
- Try running
git --version
again to see if the issue is resolved.
- Try running
These steps should fix the problem by either ensuring that Xcode is fully installed or by correctly setting up the Command Line Tools.
NOTE: If xcode-select --install gives message xcode-select: note: install requested for command line developer tools
The message xcode-select: note: install requested for command line developer tools
indicates that the system has acknowledged your request to install the Command Line Tools. Here’s what typically happens next:
-
Installation Prompt:
- After running
xcode-select --install
, a pop-up window should appear prompting you to install the Command Line Tools. - If the pop-up appears, follow the on-screen instructions to complete the installation.
- After running
-
If the Pop-up Doesn't Appear:
-
Sometimes the installation pop-up may not show immediately. If this happens, you can try the following:
-
Manually Trigger the Installation:
-
Open the Terminal and run this command:
softwareupdate --list
-
If there are updates available, including Command Line Tools, it will list them. Then, you can install them using:
softwareupdate --install --all
-
-
Manually Trigger the Installation:
-
Sometimes the installation pop-up may not show immediately. If this happens, you can try the following:
-
Verify the Installation:
-
Once the installation is complete, verify it by running:
xcode-select -p
-
The output should be
/Library/Developer/CommandLineTools
if the Command Line Tools are installed correctly.
-
-
Test Git:
- Run
git --version
to check if Git is working now.
- Run
If everything works, your Git should be functioning again. If you still encounter issues, restarting your Mac can sometimes help complete the installation process.