How to solve MacOS Git xcrun error: invalid active developer path (/Library/Developer/CommandLineTools)

How to solve MacOS Git xcrun error: invalid active developer path (/Library/Developer/CommandLineTools)

I didn't touch my mac for a while and suddenly when I try to work doing something very basic on it, the task surprisingly fails. This time, I tried to simply clone a repository using Git and the error showed up. After some research I ended up with a solution and I want to share with you the cause of this problem and how to solve it.

Before using the solution

  • Be sure to update XCode to its latest version. Some developers have claimed that this prevent this kind of error from appearing:

Install XCode Updates

Although some people say that updating XCode fix their problem, it didn't work in my case. So I had to mess up directly with the command line.

Solution

The exception is caused because of the missing developer command line tools in your system. To solve this problem, simply run the following command in your terminal:

xcode-select --install

Running this command will print the following text in the terminal:

xcode-select: note: install requested for command line developer tools

And will launch a prompt asking for confirmation to install the command line developer tools, be sure to install it:

Install XCode Command Line Tools

The installation will take a while, once it finishes, launch a new terminal (close any opened terminal) and try doing whatever you were doing before. In my case, I was simply cloning a repository with Git and it worked as expected. Personally, it's kind of ridiculous that the command line tools aren't installed by default but, anyway.

Solution for xcode-select: error: tool 'xcodebuild' requires Xcode

If you are working with Node.js and some module that requires node-gyp, you may find the following warning in your terminal:

xcode-select: error: tool 'xcodebuild' requires Xcode
but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

This error occurs when the xcode-select developer directory was pointing to /Library/Developer/CommandLineTools when a full regular Xcode was required (happens when CommandLineTools are installed after Xcode). You can easily fix this problem updating the developer directory to the Xcode.app like this:

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

Happy coding ❤️!

This could interest you

Become a more social person