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
jhnath
  • 1,033
  • 2
  • 8
  • 4
  • 1
    Possible duplicate of [Command Line Tools not working - OS X El Capitan/macOS Sierra/macOS High Sierra](https://stackoverflow.com/questions/32893412/command-line-tools-not-working-os-x-el-capitan-macos-sierra-macos-high-sierra) – Stephen Rauch Jul 02 '18 at 16:30
  • For Xcode 11.3, the following link is what needs to be downloaded. https://download.developer.apple.com/Developer_Tools/Command_Line_Tools_for_Xcode_11.3/Command_Line_Tools_for_Xcode_11.3.dmg – Giorgio Jan 29 '20 at 21:41

5 Answers5

238

This is all you need to do:

$ xcode-select --install
Arcolye
  • 6,968
  • 4
  • 34
  • 28
  • 4
    Works for Sierra too – Jazzy Jun 02 '17 at 17:34
  • 17
    Works for High Sierra too – f055 Oct 23 '17 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`. – Greg Nisbet Nov 23 '17 at 21:57
  • 25
    Works for Mojave, too! – djc Sep 25 '18 at 08:45
  • 1
    `xcode-select` - Manages the active developer directory for Xcode and BSD tools. `--install` - Opens a user interface dialog to request automatic installation of the command line developer tools. All this was taken directly from the BSD General Commands Manual (`man xcode-select`) – Bruno Robert Oct 07 '19 at 20:44
  • 27
    Works for Catalina, too! – amq Oct 09 '19 at 07:30
  • 1
    This command will update/install the latest version of Xcode developer tools for your Mac. It should generalise to many problems similar to this one, and should generally work whenever the problem arises on many, especially the most recent MacOS upgrades. My vim plugin N-vimR stopped working, and doing this fixed that too. – DryLabRebel Oct 22 '19 at 23:17
  • 2
    If I could only update this answer after every MacOS upgrade. – philshem Oct 23 '19 at 20:43
  • Really straight forward! Thanks! – Joehat Dec 06 '19 at 16:20
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

nikhilgohil11
  • 1,185
  • 15
  • 26
  • 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 May 05 '19 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 Jun 26 '19 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 – nikhilgohil11 Jun 27 '19 at 07:48
  • Happy to hear, Rene! Isn't it amazing to get reply on my 4 years old answer – nikhilgohil11 Mar 02 '22 at 09:19
  • how do I get to this menu? I can't find "Locations" or "Command line tools" in preferences. – Caleb Stanford Nov 24 '22 at 00:51
  • @CalebStanford Open Xcode and pressed " ⌘ , " it will open Settings and Second last is tab is Locations – nikhilgohil11 Nov 24 '22 at 14:08
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.

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
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.

r4m
  • 491
  • 4
  • 14
  • This worked for me. [above error occured after upgrading to Catalina from Mojave] – Oli May 24 '20 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

Hassan Hussein
  • 157
  • 1
  • 11
  • Opening Xcode, letting update some components and then making the "Command Line tool dropdown" change suggested here fixed the problem for me. – Chip Roberson Feb 17 '20 at 20:02