3033

After upgrading to macOS Sonoma, 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?

The Onin
  • 67,065
  • 4
  • 14
  • 18
  • 248
    I was really confused that the question is 5 years old but says "after upgrading to macOS Monterey," which was released less than a month ago. Then I checked the edit history and it looks like you're updating it with each new release. Good on you, sir. – Travesty3 Nov 08 '21 at 17:03
  • 97
    You sir are a real gentlemen! Doing this for 5 years, and updating your question, amazing! – Tancho Nov 08 '21 at 18:06
  • 21
    @Travesty3 haha me the same. I just joined appleExchange only to upvote. – jabujavi Nov 09 '21 at 10:51
  • 19
    Wow! You kept updating this question for 5 years? This is the best post I have seen so far on Apple Stack Exchange – O5 Command Stands With Ukraine May 04 '22 at 21:00
  • 15
    @Travesty3 I'd like to point out that he's also the author of the accepted answer :) – mrzool Jun 14 '22 at 13:42
  • 6
    Same here. I upgraded my macOS to Ventura and faced this issue when I tried running git command. I was shocked to see this query was posted 6 years ago and had quickly went through the comments only to realise that you are updating the query for every new version. Cool :) – Akhil Oct 25 '22 at 16:22
  • 2
    You are actually a legend, made an account here just to tell you that lmao. – TedTran2019 Nov 04 '22 at 07:17
  • 1
    Thanks for updating the title, but instead of revisiting ever so often, why not say "... after updating mac os"? That is, leave the version off and make it general? – Chad Mx Nov 25 '22 at 03:33
  • 2
    @ChadMx googlebot likes h1 – The Onin Dec 14 '22 at 16:29
  • 2
    7 years and counting! Good job! – Den Drobiazko Jan 19 '23 at 11:55
  • 1
    i got same problem when uninstall xcode lol 2023 – Yogi Arif Widodo Feb 19 '23 at 15:08
  • 3
    every macos update I'm here – crystalbit Mar 12 '23 at 18:49
  • 1
    Dammit, after every single upgrade I google similar error and solution is the same command. I that so difficult to make it part of the upgrade? – DonPaulie Mar 27 '23 at 20:46
  • 1
    let me think... this question was asked 7 years ago, and it is now updated for macOS Sonoma. So that means this hasn't been solved for 7 years and Apple is still well and alive and thriving. For me, I had git running well and then I updated from an old Ventura to the latest Ventura, and git stopped working – nonopolarity Jan 11 '24 at 07:55

8 Answers8

4007

Solution

Open Terminal, and run the following:

xcode-select --install

This will pop a dialogue box, Select "Install", and it will download and install the Command Line Tools package and fix the problem. (The popped Window may be behind other windows.)

You do not need Xcode, you can install only the Command Line Tools here, it is about 130 MB (600 MB as of Xcode v14.1).

If the above alone doesn't do it, then also run:

sudo xcode-select --reset

Further reading

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.

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

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

You may get an error message: "Can't install the software because it is not currently available from the Software Update server". In this case xcode-select --reset works as pointed by akozin.

The Onin
  • 67,065
  • 4
  • 14
  • 18
  • 13
    I also had to run sudo xcodebuild -license accept – a113nw Dec 29 '20 at 19:07
  • 2
    solved my "Can't install the software" issue that occured with sudo xcode-select --install. – jerik Feb 11 '21 at 23:51
  • 1
    xcode-select --install solved my issues with Git command. Issues was after update from macOs 11 to 12. – PriyankMotivaras Nov 03 '21 at 04:58
  • 9
    It happens after updating macOS from Bigsur to Monterey. – anaszaman Nov 03 '21 at 12:00
  • 125
    "218 hours remaining" wtf... :O :D :D – OZZIE Nov 25 '21 at 18:51
  • 1
    I did the xcode-select --install and xcode-select --reset but still didn't work until I opened a new terminal window in which git init finished successfully. – Erikun Jan 14 '22 at 09:04
  • 2
    No need to download Xcode. I am using MacOS Monterey version 12.x. I have downloaded "Command Line Tools for Xcode 13.3 beta". Restarted terminal and command line is working along with github clone/pull/push issues. It worked like charm. – Kamlesh Feb 05 '22 at 09:10
  • 1
    This worked for me after installing Xcode completely borked my dev environment. Now I'm running "Apple Git". Fun stuff. :/ – Matt West Apr 16 '22 at 10:19
  • 11
    I tried this and it did not work... until I realised it had opened a window that had been lost under others, where I had to click to install and to accept the T&Cs. Once I did and installed everything (127h... but it was more like 40' in the end) git started working again. If the commands do not seem to work for you, look for a misplaced window! – sergut Aug 20 '22 at 18:36
  • 2
    really bad error message. this is not the first time i've ended up here. :/ – keithpjolley Nov 02 '22 at 23:12
  • 5
    Not working for me. When I run xcode-select --install, then select "Install" to install just command line tools, (NOT "Get Xcode" because I don't want xcode), then agree to the license, then it tries to download a 5GB thing. Could you be more specific on how to install ONLY this 130 MB thing? – dinosaur Nov 03 '22 at 22:33
  • @dinosaur same here, except it tried to download a 21GB thing. I would settle for 5GB... – Mouradif Nov 22 '22 at 16:04
  • Happened to me again after upgrading to MacOs Ventura. Thankfully I found this answer again! – judehall Feb 02 '23 at 21:13
  • i have uninstall xcode and i get the message its guide me todo install standalone mode. btw thanks for reset commands . – Yogi Arif Widodo Feb 19 '23 at 14:14
  • 1
    but why the loading is 96 hours 30 minutes remaining ? – Yogi Arif Widodo Feb 19 '23 at 14:15
  • can't install the software after run xcode-select --install – Yogi Arif Widodo Feb 19 '23 at 15:09
  • xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance – Yogi Arif Widodo Feb 19 '23 at 15:21
  • i use ventura 13.2 mbp m1 – Yogi Arif Widodo Feb 19 '23 at 15:25
  • works on MacOS Catalina (Mac Pro Mid-2012) – gia huy Mar 21 '23 at 14:41
  • 1
    I had the same problem when I updated to Venture. No idea why. It solved perfectly by installing xcode again. Thank you. – Thiago Apr 24 '23 at 06:49
  • 4
    For anyone who gets " xcode-select: note: install requested for command line developer tools" and think nothing happens, make sure you check for a popup that allows you to click install. I had a bunch of stuff on my screen and didn't notice it so kept going in circles for a bit – Programmermatt May 19 '23 at 15:00
  • 1
    Turn off VPN if you can, to speed up this install/download – cellepo Sep 29 '23 at 18:52
103

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/all/ 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

michalczukm
  • 3,487
  • 2
    I am using MacOS Monterey version 12.x. I have downloaded "Command Line Tools for Xcode 13.3 beta". Restarted terminal and command line is working along with github clone/pull/push issues. Your solution worked like charm. Thanks a lot dear. – Kamlesh Feb 05 '22 at 09:09
  • This is the best solution. On Monterey, xcode-select --install immediately tries to install 20+GB of data so downloading from apple website is the only way – Mouradif Nov 25 '22 at 16:03
76

For macOS High Sierra, just run the same command:

xcode-select --install

and everything will get back to work.

2019 UPDATE: This is needed for every new macOS version, so it'll work for Catalina as well.

40

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.

  • 1
    softwareupdate -l will show a list like * Label: Command Line Tools for Xcode-13.2 and then you can pick the specific one by using the text after * Label:, e.g. softwareupdate --install "Command Line Tools for Xcode-13.3" – jaygooby Apr 13 '22 at 10:27
27

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

Then all git stuff ran smoothly.

NoelAbey
  • 389
22

xcode-select --install and xcode-select --reset didn't work for me.

I had to download it manually from Apple Developers website: https://developer.apple.com/download/

Choose the Command line of your current OS.

Screenshot for link

Rahul
  • 3
  • 2
Steffi
  • 441
  • 4
  • 4
  • Direct link: https://download.developer.apple.com/Developer_Tools/Command_Line_Tools_for_Xcode_13.4/Command_Line_Tools_for_Xcode_13.4.dmg – Lonely Jul 19 '22 at 12:24
19

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.

mirth23
  • 291
0

I had a different situation/solution...

My command line tools have been installed for ages. Been using/relying on them for years. But, then, suddenly ... things weren't working. I tried these solutions to no avail.

Turns out, I had moved Xcode to "/Applications/Added Apps" folder (I like to keep track of what I added vis-à-vis the ones that came pre-installed) and lo! that was the problem.

I put it back and all things worked again.

Kinda don't like how certain things expect an app to be in a certain location, especially if I just it in a subdirectory. sheesh.