After upgrading to macOS Sierra (and later Mojave), I tried to run git from Terminal but it kept giving me the following error:

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun.

How do I fix it?

up vote 1387 down vote accepted

Open Terminal, and run the following:

xcode-select --install

This will download and install xcode developer tools and fix the problem. The problem is that one needs to explicitly agree to the license agreement. As a follow on step, you may need to reset the path to Xcode if you have several versions or want the command line tools to run without Xcode.

xcode-select --switch /Applications/Xcode.app
xcode-select --switch /Library/Developer/CommandLineTools

I found the solution in this question, Command Line Tools not working.

  • 140
    This solution dit not help me. I tried xcode-select --reset and it helped! – akozin Dec 30 '16 at 20:13
  • 33
    helped me after upgrading to macOS High Sierra and tried to run git status – Felix Geenen Sep 28 '17 at 0:36
  • 6
    Also consider brew update if you have it installed. – Mausy5043 Oct 7 '17 at 11:30
  • 6
    Just solved the same issue when I upgraded from Sierra to High Sierra. I first try --reset but that didn't make any difference. --install solved it! – iaforek Nov 13 '17 at 9:52
  • 13
    Still applies to macOS Mojave! I think every year I come back to this post. – Eric Majerus Jun 30 at 1:33

If you don't want to install nor use Xcode (I don't) you can install only command tools for Xcode (please see Edit)

Preconditions:

  • you have AppleID

Solution

Go to https://developer.apple.com/download/more/ and find Command line tools OS X 10.11) for Xcode 7.1. Then install downloaded .dmg package.

Newer versions

It should work with newer versions of Command line tools OS X however I tested it Command line tools OS X 10.11) for Xcode 7.1 particular version.

Update to macOS 10.13

After updating do macOS 10.13, I had to install Command Line Tools (macOS 10.13) for Xcode 9 - also works great.


Edit

As @setholopolus mentioned in comment,

xcode-select --install

Also installs only command line tools for Xcode.

You can also verify this at: http://osxdaily.com/2014/02/12/install-command-line-tools-mac-os-x/

I am leaving my answer in case you'd have problems with installation via cli.


PS credits to this SO answer: https://stackoverflow.com/a/33593066/2029818

  • 1
    You'll need to log in with your Apple ID in order to complete the download. – james.garriss Dec 20 '16 at 12:29
  • Yes. But for me that's not the issue. The issue is that I don't want to install full Xcode. I'll update the answer with this info – michalczukm Dec 20 '16 at 15:02
  • 1
    @michalczukm I'm on macOS 10.12.5 and installed the latest version (I think it was CLT for macOS 10.12 for Xcode 8.3) and it worked fine. Problem solved, thank you. – Mark Simpson Jun 13 '17 at 9:48
  • 1
    Running xcode-select --install, as the other answer states, doesn't install Xcode, just the command line tools. – setholopolus Dec 6 '17 at 19:42
  • 1
    For macOS Mojave, xcode-select --install didn't work for me. But Since 30 July 2018, you can get the newest version of command line tools for macOS 10.4 (Mojave) once you login into the Apple Developer Account. – Agile Bean Aug 3 at 16:52

For macOS High Sierra, just run the same command:

xcode-select --install

and everything will get back to work.

I tried the xcode-select --install but I was forced to install it from the App Store.

Then all git stuff ran smoothly.

The accepted answer is correct, but also note that git does not make it obvious if the error is coming from remote or from local. If you are running OS X on your remote, your install problem may be on the remote side and you'll see the same error on git clone and git pull but NOT on git status.

Here are the steps I needed to go through for Mojave:

First xcode-select --reset.

Next I needed to upgrade xcode tools to the latest version: sudo softwareupdate -ia --verbose (NB: this runs all available updates from the app store, there is a way to specify that you only want to update one app/program, but I don't know it off the top of my head).

You can try this command another time if it shows some inconsistent behaviour during the first try.

Finally verify that it worked by using a git command of your choosing, e.g. git status.

  • yes, this solves the issue from High Sierra to Mojave. Just after that, run sudo xcodebuild -license – xyz Oct 7 at 23:03

protected by Community Sep 26 '17 at 15:26

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.