102

I ran into this error trying to push to git, when I typed git init.

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

I tried the following solutions.

xcode-select —install
sudo xcode-select -switch
sudo xcode-select —install
brew doctor
brew update
brew upgrade
brew cleanup
2

5 Answers 5

237

This is all you need to do:

$ xcode-select --install
8
  • 4
    Works for Sierra too
    – Jazzy
    Commented Jun 2, 2017 at 17:34
  • 17
    Works for High Sierra too
    – f055
    Commented Oct 23, 2017 at 21:30
  • 2
    What does running xcode-select --install actually do / how does the license check work? I checked the md5 of one of the covered executables (in my case make) and it's the same before and after running xcode-select --install. Commented Nov 23, 2017 at 21:57
  • 25
    Works for Mojave, too!
    – djc
    Commented Sep 25, 2018 at 8:45
  • 27
    Works for Catalina, too!
    – amq
    Commented Oct 9, 2019 at 7:30
41

You can select command line tools from the XCode Preferences shown in the screenshot below.

You will get a prompt for password.

enter image description here

6
  • 1
    I moved my XCode to another ssd. After that I got the error message when trying to use git. Your solution is very quick and solved the problem!
    – laka
    Commented May 5, 2019 at 18:04
  • I had 2 of the same option/version/id in this field, chose first one instead of selected second one, and it worked (I previously updated xcode from appstore as opposed to my initial manual DL installation, guess this is what messed it up after a simple react native library installation/linkage)
    – sed
    Commented Jun 26, 2019 at 21:37
  • Yes, you are right, in your case maybe there are two command line tools and react native is looking for an installed tool which is not selected in Xcode. Btw I'm happy that you solved the issue Commented Jun 27, 2019 at 7:48
  • Happy to hear, Rene! Isn't it amazing to get reply on my 4 years old answer Commented Mar 2, 2022 at 9:19
  • how do I get to this menu? I can't find "Locations" or "Command line tools" in preferences. Commented Nov 24, 2022 at 0:51
25

1)

try typing in "xcode-select -print-path" and see if the path you see is the path you're expecting for your current Xcode version.

2)

If you go to:

https://developer.apple.com/downloads/

(you'll need to sign in with your Apple Developer account)

Once there, you'll see links for "Command Line Tools". It sounds like you need to install MacOS 10.11 Command Line Tools for Xcode 7.

3
  • 1
    I had the same issue when upgrading from El Capitan to Sierra, and the solution was the same: download Sierra's version of the Command Line Tools.
    – mystery
    Commented Sep 24, 2016 at 1:29
  • 2
    Same goes for the just-released Mojave. Thanks!
    – Nikita
    Commented Sep 25, 2018 at 12:28
  • Same solution for Catalina! Commented Nov 15, 2019 at 19:12
4

Try:

sudo xcode-select -r

in this way it unsets any user-specified developer directory, so that the developer directory will be found via the default search mechanism.

1
  • This worked for me. [above error occured after upgrading to Catalina from Mojave]
    – Oli
    Commented May 24, 2020 at 18:20
3

If you have Catalina and Xcode 11 and you have this problem, then go to Xcode Preferences and select Location tab, check that the Command Line tool dropdown has Xcode 11.0 selected. If Xcode 11 is not there then you need to download and install Command-line tools for Xcode 11 here (choose the correct Beta)

https://developer.apple.com/download/more/?=command%20line%20tools

1
  • Opening Xcode, letting update some components and then making the "Command Line tool dropdown" change suggested here fixed the problem for me. Commented Feb 17, 2020 at 20:02

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