3414

I updated to the latest OS, and/or restarted my computer (this happens on every major update, but this time all I did was restart my computer on 2022-09-13).

This morning I navigated to my work's codebase in the command line on my MacBook Pro, typed in "git status" in the repository and received an error:

(In 9/2022, this error was much different, but I didn't capture it)

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

Git will not work!

How do I fix Git, and the command-line tools?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
dustbuster
  • 79,958
  • 7
  • 21
  • 41
  • 3
    This is more of a git problem than a macOS problem. – dustbuster Jan 14 '19 at 06:17
  • 12
    Possible duplicate https://apple.stackexchange.com/questions/254380/why-am-i-getting-an-invalid-active-developer-path-when-attempting-to-use-git-a – markroxor Jul 01 '19 at 05:28
  • 238
    to be honest, this problem is something APPLE should take care of. They create it, they should fix it !!!!! Asking everyone to run that command everytime this happens isn't an Good/Correct option. Not to mention you need to download that big chunk for git only. – windmaomao Feb 04 '21 at 14:30
  • 6
    I didn’t run into it on my update to Big Sur. Only had this problem the year when I originally wrote this Q&A. I’ve just been updating it every year to include the latest changes. – dustbuster Feb 05 '21 at 05:07
  • If you don't have Xcode, only installing Xcode command line tools will solve the problem. https://developer.apple.com/download/more/?=command%20line%20tools – alianjum0 Feb 08 '21 at 09:18
  • alianjum0, thanks for that. I just went down a huge rat hole being unable to install XCode from the AppStore (long story). Being able to install just the CLI saved the day! – Roy Smith Mar 13 '21 at 02:02
  • 12
    We should get paid by apple for debugging their code! – Nir Apr 01 '21 at 09:46
  • It's a failure to completely update ALL their software during a major version update. I have not run into this since i initially made the question and answer! So it works on some level i suppose! – dustbuster Apr 01 '21 at 13:33
  • 1
    @dustbuster No. It's not a problem with git. It's a macOS problem. You get the same error from other commands like make. The solution is what I thought it was but I checked here anyway as I wanted to be sure - too much going on to worry about possible fixes. – Pryftan Oct 26 '21 at 14:48
  • 4
    Another OS update and yet 3 years later, issue still exist. – Vaulstein Nov 02 '21 at 08:50
  • 31
    I updated to Monterey and faced the same issue. Apple really needs to look into this issue. – thisisshantzz Nov 02 '21 at 23:37
  • 2
    I never had this issue before and I've been using macOS since about the last 3 years. However I just updated it to Monterrey and it broke git. – iamnicoj Nov 11 '21 at 14:27
  • "This is more of a git problem ..." how so? git is merely a command line tool. I've used git on other platforms for decades and have never encountered this issue until working on a Mac. What the hell does git have to do with XCode? – Derek Greer Dec 16 '21 at 15:52
  • 1
    I wrote that 3 years ago matey! lol But yea. it's totally a macOs problem. I did not think this would be a relevant for 3 years! – dustbuster Dec 17 '21 at 20:08
  • Is there some issue/ticket in an Apple help system that we can upvote to try to get more attention on this? – rkechols Jan 26 '22 at 17:07
  • 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
  • 4
    Again the same problem with Ventura! Come on, Apple! – Upendra Oct 27 '22 at 13:30
  • 1
    I'm also having the same problem with Ventura @Upendra. If this happens with every macOS update (it breaks Git), it would be nice if someone could at least write a nice blog post about this... – seeker_after_truth Oct 31 '22 at 22:29
  • 1
    I had the problem with Ventura as well. Solution for me was to launch the Xcode app once. – Joscha Fregin Nov 02 '22 at 10:42
  • Every year around fall i got a huge surge of rep from this Q and A. you'd think developers would be the one group of folks they want to make happy. I think some of my counter answers are right. Switch to Brew, forget about this problem forever! I do like the simulate phone feature of xocde. I think that's worth having, but other than that, i do not need x-code! – dustbuster Dec 13 '22 at 14:59
  • 1
    apple somehow seems to be discouraging developers to use a mac without xcode ! this is outright monopilistic behaviour. The only thing apple is notorious for. – Lazarus Thurston Jan 05 '23 at 11:55
  • All hail the apple and its PITA git! lol – dustbuster Jan 06 '23 at 13:16

38 Answers38

5010

The problem is that Xcode Command-line Tools needs to be updated due to OS update.

  • UPDATED for Ventura!!

After opening the terminal after a restart, I tried to go to my code, and do a git status, and I got an error and prompt for command line software agreement.

So press space until you get to the [agree, print, cancel] option, so careful hit space to scroll down to the end, if you blow past It you have to run a command to get it back. Use sudo xcodebuild -license to get to it again.

Just be careful on scrolling down and enter agree and press return and it will launch into an update.

Xcode software license

Then I tried to use git after the install, and it prompted me to install Xcode tools again.

I followed my own advice from previous years (see below), and went to https://developer.apple.com/download/all and downloaded "Command Line Tools for Xcode 14" (You have to log in with your Apple ID and enter MFA code, so have all the devices you need for that handy. Then select "Command Line Tools for Xcode 14", or if you want to get into the alphas or betas, that's up to you. But stable releases are probably the best choice for software developers.

developer download page selection for "Command Line Tools for Xcode 14"

You have to either download the tools from CLI or the developer page and before you can use git, you need to reboot!!! Or you will get stuck in a loop of prompt & downloading

Rebooting will break the loop and complete the installation of your CLI tools including git so that you can get back to work

Solutions for previous years, these may or may not be valid these days as the downloads page has changed significantly:

PREVIOUS YEARS SOLUTIONS, probably #2 is most helpful.

*** Solution #1:

Go back to your terminal and enter:

xcode-select --install

You'll then receive the following output:

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

You will then be prompted in a window to update Xcode Command Line tools. (which could take a while)

Open a new terminal window and your development tools should be returned.

Addition: With any major or semi-major update you'll need to update the command line tools in order to get them functioning properly again. Check Xcode with any update. This goes beyond Mojave...

After that restart your terminal

Alternatively, IF that fails, and it might.... you'll get a pop-up box saying "Software not found on server", proceed to solution 2.

*** Solution #2: (Preferred method)

If you hit xcode-select --install and it doesn't find the software, log into Apple Developer, and install it via webpage.

Log in or sign up here:

https://developer.apple.com/download/more/

Look for: "Command Line Tools for Xcode 14.x" in the list of downloads Then click the dmg and download. (See previous image above) either way, you will probably wind up at an apple downloads webpage.

dustbuster
  • 79,958
  • 7
  • 21
  • 41
  • 76
    This fixed the issue I had with Microsoft Visual Studio Code which was complaining about Git not being installed when I first launched it after upgrading to Mojave. I thought the issue was VS Code, but it was the issue in this SO question. Restarting VS Code after installing the Xcode Command-line Tools solved the issue. – Mark Oct 10 '18 at 00:36
  • 405
    I wish the Xcode update was part of the OS update. Something like this happens every time I upgrade. Annoying. – mvndaai Dec 14 '18 at 17:17
  • It's happened to me on every update. I guess the majority of Mac users don't have Xcode installed! Otherwise apple probably would update it at the same time. . – dustbuster Dec 14 '18 at 18:19
  • 24
    Definitely annoying though. A simple check for Xcode installation and then an update during the OS update would be pretty simple to add. It's always something with these OS updates from Apple. You'd think they'd have figured it out by now. – zgr024 Dec 14 '18 at 20:53
  • 4
    In case you installed GIT and this is still not working you might need to add an alias: `sudo xcode-select -s /Library/Developer/CommandLineTools` – Miguel Garrido Dec 30 '18 at 16:52
  • 2
    I'd already visited the App Store, and it claimed to find no updates. Why can't it recognize that Xcode needs to be updated? – Jim Van Zandt Jan 28 '19 at 13:16
  • 21
    For anyone using Git in PHPStorm; you need to restart PHPStorm after running `xcode-select --install`. Then it'll work. – Daan van den Bergh Feb 13 '19 at 07:20
  • Same SVN issue got fixed by this method as well. – yantaq May 14 '19 at 17:27
  • When I go to install (after agreeing to T's & C's) I get "Can't install the software because it is not currently available from th Software Update server." Has anyone else gotten this? – James Jun 06 '19 at 12:52
  • I did not need to restart my terminal btw. – SuryaVal Jun 07 '19 at 16:38
  • Nothing is working for me. I am using Sourcetree on same repository. it shows the username and email correctly. – ashishn Jun 15 '19 at 07:33
  • For me running `open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg` after the `xcode-select --install` command worked, following [this stackoverflow answer](https://stackoverflow.com/questions/52509602/cant-compile-c-program-on-a-mac-after-upgrade-to-mojave) – Forcetti Aug 27 '19 at 18:23
  • 73
    This solution works for me for Mac Catalina update also. Superb!!! – Shahnaz Khan Oct 08 '19 at 16:55
  • I updated the text to just say "MacOs update" I am very happy it works for Catalina! Figured it would! – dustbuster Oct 10 '19 at 01:30
  • just wanted to add that you need to restart the computer, also a good `brew doctor` may also help find any issues – luis19mx Nov 14 '19 at 16:27
  • I am using android studio on Mac, recently updated OS to Catalina. After updating OS, stop connecting to Version Control (subversion). But thanks to @dustbuster, installing xCode solve the my problem. – Hiren Dabhi Nov 23 '19 at 10:54
  • But why ? Why do we need to do this ? my question is to Apple falks – Ugur Kazdal Dec 19 '19 at 10:48
  • Should I do the same with zsh too ? – Tilak Madichetti Dec 23 '19 at 08:40
  • You will not have to do anything to zsh Tilak. The issue is git. Not zsh. – dustbuster Dec 23 '19 at 18:05
  • After the update , you need to make sure to restart all the applications and IDE that depend or have connection with git like all IntelliJ IDEs ,sublime with git , source tree etc to make it run properly, – Taher Khalil Dec 25 '19 at 11:30
  • 3
    If you have Xcode installed, you **do not need the separate command line tools install**. Just make sure you run `xcode-select --switch /Applications/Xcode.app/Contents/Developer` or `xcode-select --reset` so Terminal will use the command line tools inside Xcode instead of the ones installed by the "command line tools" standalone installer. From then on, the App Store will auto-update Xcode and your tools will stay current. – uliwitness Feb 15 '20 at 10:50
  • 1
    _July 2020 Update_: This answer worked for me on Mac OS Mojave (after upgrading from El Captain). Takes a while to install though. (Just doing `xcode-select --reset` as mentioned in other answers did not work for me) – Anupam Jul 07 '20 at 07:38
  • The way apple manages the xcode downloads has changed. I actually ran into this myself AGAIN when i upgraded this year! So i updated the answer not too long ago. – dustbuster Oct 22 '20 at 18:26
  • For PyCharm also need to do like PHPStorm as suggested by @DaanvandenBergh . That is need to restart PyCharm after running `xcode-select --install` – Md. Abu Nafee Ibna Zahid Nov 08 '20 at 06:42
  • 1
    Upgraded to macOS Big Sur and here it is again. – larrydalmeida Nov 17 '20 at 10:40
  • 1
    I have updated this answer every year! Check out solution #2, that's probably the most relevant. There's a surge this time every year! – dustbuster Nov 17 '20 at 16:49
  • 1
    I had to download `Command_Line_Tools_for_Xcode_12.3_beta.dmg` for MacOS 11.1 Big Sur. Then it worked perfectly. – geekhunger Nov 24 '20 at 09:26
  • Glad to hear! I have not updated yet. is that the name of the download file now? – dustbuster Nov 30 '20 at 19:52
  • 1
    thanks a lot! I immediately went for solution 2 once I read that solution 1 might very well fail haha. – Emile Beukes Jan 05 '21 at 10:42
  • Most Excellent! I actually didn't run into it this time around when I updated to Big Sur. – dustbuster Jan 05 '21 at 19:39
  • How could Git is not part of OSX? If not, then make it never part of OSX? what's the benefits of bundling a developer tool in the operation system which is not responsible for updating it? – windmaomao Feb 04 '21 at 14:29
  • Awesome! Solution #1 works for me. Thanks :) It's so annoying to do this after every minor update. Techies at Apple Listen O Listen !! – Anand Mar 14 '21 at 15:06
  • 1
    You should not have to do it after every update, that is annoying!! – dustbuster Mar 15 '21 at 12:07
  • I update Xcode to Version 12.5 (12E262), which is the latest one. And I get this same error. Does it means I need to do `xcode-select --install` each time manually? – Zhou Haibo Apr 30 '21 at 10:55
  • 1
    `xcode-select --install` + terminal restart fixed broken git after Catalina -> Big Sure update! – pawelswiecki May 13 '21 at 12:16
  • Solution 1 worked for me running macOS 11.5.1. Thank you :D – Jesse Aug 16 '21 at 21:57
  • on the update to monterey, it worked like a charm (xcode-select --install). Thank you so much!! – Luan Cardoso Nov 01 '21 at 12:50
  • I updated from macOS Big Sur -> macOS Monterey, Nov 01, 2021. Same problem with git: `xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun`. This installation solved the problem: `xcode-select --install` THANK YOU!!! – Silvia42 Nov 02 '21 at 01:11
  • 1
    I cannot believe this problem has not been solved in November 2021. Apple WTH? – Samuel Nde Nov 13 '21 at 21:32
  • I updated recently to MacOS Monterey , and this update of xcode tools was able to fix this exact same issue. Thank you. – Erich Meissner Dec 21 '21 at 19:47
  • 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:11
  • I never understood why XCode is required for git or why it interferes with my git installation in the first place. I tried to uninstall Xcode completely to avoid this situation, but that did not work out well – ChrisRich Mar 07 '22 at 00:58
  • For iOS Monterey, I went with 13.3.1. And git started working again. – Eric Manley Apr 11 '22 at 21:38
  • Works perfect with macOS Catalina – Xab Ion May 05 '22 at 03:50
  • My first dev job was in .Net. I remember thinking Visual Studio was huge and invasive. It's got nothing on Xcode. – Matt West May 31 '22 at 02:53
  • Yep I feel the same way! I learned how to code in college using Visual Studio. Now if I accidentally double click a file that's registered to open with Xcode I go right for the force quit! Do not pass go and no 200 bucks for you! – dustbuster Jun 01 '22 at 13:56
  • 1
    I recently upgraded to Monterey 12.5 and I did not need to restart my iterm2 so maybe add a step to check before restarting – Jeff Aug 10 '22 at 17:26
  • The first option requires 15GB of space to install. any other way? – user9437856 Aug 23 '22 at 09:52
  • Deja vu, wow. Every bigger Mac update I'm back here... This should get fixed at some point. – RincewindAssoc Aug 25 '22 at 09:07
  • 1
    This worked for me after the macOS Ventura 13.0 update. – Vedha Viyash Oct 25 '22 at 23:11
  • 3
    All I had to do was to go to Xcode - Preferences - Locations and select the Command Line Tools from the dropdown that was empty, after updating to macOs Ventura. – Antonio Brandao Oct 27 '22 at 12:52
  • 1
    @mvndaai I'm so confused why xcode wouldn't update with a macOS update. Isn't xcode also produced by apple? https://developer.apple.com/xcode/ – seeker_after_truth Oct 31 '22 at 22:35
  • You don't have to update Mac to update Xcode, when you update macOS first, like to Montery, you have to update Xcode. – dustbuster Nov 01 '22 at 13:09
  • Wow, I'm stuck without git on my mobile data plan (on a trip). I don't use any Apple dev tools. This is embarrassing... – Damien Mar 05 '23 at 10:42
  • Damien Maybe Install git using brew. Much less downloading! I think how to do that is below somewhere! – dustbuster Mar 07 '23 at 15:22
  • 1
    Your link "https://developer.apple.com/download/all/?q=Command%20Line%20Tools" is actually linked to "https://developer.apple.com/download/more/" And your text says download "Command Line Tools" but the screenshot highlight "Additional Tools" – Junye Huang Mar 08 '23 at 10:58
  • Image and link updated ^^ stuff changes at developer.apple all the dang time! – dustbuster Mar 08 '23 at 15:31
  • Along with this great answer, I had to follow the advice on this post first, then I was able to run the `xcode-select --install`: https://stackoverflow.com/questions/55939354/tool-xcodebuild-requires-xcode-but-active-developer-directory-library-devel – Jav Jun 20 '23 at 20:59
  • This Q & A has gotten me nearly 80K in rep! Thanks to all for the upvotes! I love you all! – dustbuster Jun 30 '23 at 16:36
367

I got some errors that the software was unavailable from the update server when trying

xcode-select --install

What fixed it for me was going here https://developer.apple.com/download/more/ and downloading Command Line Tools (macOS 10.14) for Xcode 10 and then installing it manually.

After that, the errors should be gone when you open up a new terminal.


Update for macOS Ventura 13.0.1 (Nov 2022)

Install Command Line Tools for Xcode 14.1

Somu
  • 3,593
  • 6
  • 34
  • 44
deef
  • 4,410
  • 2
  • 17
  • 21
  • 15
    This should be the right answer, tried on 3 machines and @dustbuster answer doesn't work anymore and it shows "software was unavailable from the update server when trying" – user2577923 Nov 02 '18 at 14:17
  • 9
    For me this ends with `software not available at server` but @High6's answer below works. `xcode-select --reset` – briankip Nov 04 '18 at 14:59
  • downloading ``Command Line Tools (macOS 10.14) for Xcode 10.1`` from the link. thanks! – Xavier Ojeda Aguilar Nov 04 '18 at 21:33
  • 2
    Had xcode installed still there were issues. This worked like a charm... should be the selected answer. Or should be addendum to top answer. – AmitM Nov 22 '19 at 11:43
  • 2
    This also works for macOS 10.15.2. Though I had to select `Command Line Tools for Xcode 11.3`, since Xcode 10.1 wasn't available – Rachel Lanman Dec 13 '19 at 21:04
  • On Mac OS 10.15.6 Catalina, this was the solution that worked for me. (Command Line tools for Xcode 12 if you're on Catalina - skip the mammoth Xcode 12 app download) – jkix Sep 21 '20 at 16:25
  • Resolved same issue for me. – Learner Nov 14 '22 at 15:59
  • On macOS Ventura 13.0.1, this also resolved for me by installing Xcode from the App Store. – Boaz Nov 30 '22 at 09:03
  • Your update for macOS Ventura helped me out. It seems, that even restarting is unnecessary. – Igor Dec 02 '22 at 00:05
  • Above command itself worked for Vetura as well without restarting – Kiran JD Dec 29 '22 at 09:31
  • Even though I was able to `xcode-select --install` for Ventura, I was not able to push anything. Downloading the command line tools pkg installer did work for me. – Vladimir Vargas Mar 27 '23 at 13:29
180

For me xcode-select --reset was the solution on Mojave.

disco crazy
  • 31,313
  • 12
  • 80
  • 83
110

In addition to dustbuster's answer I needed to set path to the Xcode folder with this command:

sudo xcode-select -switch /Library/Developer/CommandLineTools
Patrik Neperfekta
  • 1,201
  • 1
  • 7
  • 5
  • 2
    Yep same for me, @dustbuster might be a good idea to merge these answers. – James Oct 19 '18 at 19:30
  • Ok this one solved this for me. Tried `xcode-select --install` and downloading and installing manually, none of the solutions worked. Note that I waited and upgraded to version 10.14.1. – mpiktas Nov 19 '18 at 17:38
  • 4
    If you have Xcode installed, you **do not need the separate command line tools install**. Just make sure you run `xcode-select --switch /Applications/Xcode.app/Contents/Developer` or `xcode-select --reset` so Terminal will use the command line tools inside Xcode instead of the ones installed by the "command line tools" standalone installer. From then on, the App Store will auto-update Xcode and your tools will stay current. – uliwitness Feb 15 '20 at 10:51
  • been through so many answers, this is the one that worked for me after the Mojave update, thanks! – mobcity zkore Aug 27 '20 at 23:27
93

updated from Mojave to Big Sur and got the same error : the command

xcode-select --install

worked like a charm

Abderrazzak Nejeoui
  • 1,496
  • 12
  • 9
64

After upgrade to Mac Catalina I faced the same issue, I had to run couple of commands to get this fixed.

First started with:

xcode-select --install

It didn't fix the problem, had to run the following in sudo

sudo xcode-select --reset

Then, finally got fixed after I switched and set the path explicitly for active developer directory:

sudo xcode-select -s /Library/Developer/CommandLineTools

Note: In case you have Xcode installed, you may need to specify Xcode directory in this case, it should be something like this

xcode-select -s /Applications/Xcode.app

Muhammad Soliman
  • 21,644
  • 6
  • 109
  • 75
  • If you have Xcode installed, you **do not need the separate command line tools install**. Just make sure you run `xcode-select --switch /Applications/Xcode.app/Contents/Developer` or `xcode-select --reset` so Terminal will use the command line tools inside Xcode instead of the ones installed by the "command line tools" standalone installer. From then on, the App Store will auto-update Xcode and your tools will stay current. – uliwitness Feb 15 '20 at 10:58
  • Xcode select did it since I only had the beta version installed! – gurehbgui Aug 09 '20 at 18:00
  • Try `sudo xcode-select --reset` first then `--install` – Thomas Beauvais Nov 23 '21 at 14:19
54

For me what worked is the following:

sudo xcode-select --reset

Then like in @High6's answer:

sudo xcodebuild -license

This will reveal a license which I assume is some Xcode license. Scroll to the bottom using space (or the mouse) then tap agree.

This is what worked for me on MacOS Mojave v 10.14.

jpsecher
  • 4,461
  • 2
  • 33
  • 42
briankip
  • 2,502
  • 2
  • 23
  • 26
  • your solution worked for me on MacOS 10.13 High Sierra. Thank you. – Daniel Jan 01 '20 at 19:46
  • If you **have Xcode installed**, this is the correct solution. Terminal will use the command line tools inside Xcode instead of the ones installed by the "command line tools" standalone installer. From then on, the App Store will auto-update Xcode and your tools will stay current. – uliwitness Feb 15 '20 at 10:54
  • This is working for BigSur as well as the Monterey beta branch. Way easier than downloading and installing giant new Xcode releases each time you update. – jacksonbenete Jul 30 '21 at 22:15
  • This did the trick for me and fixed VSCode not finding Git after I migrated from my old iMac running Catalina to my shiny new Apple Silicon MacBook Pro running Monterey via Migration Assistant. – VirtualWolf Nov 13 '21 at 09:30
53

If you use xcode then install it (~12GB)

xcode-select --install

Otherwise install latest command line tools (~500MB)

Downloads

Update: If struck in install loop

xcodebuild -runFirstLaunch
Chenna
  • 2,383
  • 3
  • 20
  • 36
  • 3
    I've (re)installed xcode so many times over the past 2 years that it's like "How many times do I have to teach you this lesson, old man?" – Cameron Hudson Jul 02 '21 at 02:06
52
  • if there are several versions, select one of them from: xcode -> Preferences and tap Locations then select, as the followng image

enter image description here

taha
  • 769
  • 6
  • 5
  • This fixes a couple items, but not all – Murwa Aug 13 '19 at 18:20
  • I had Xcode 10.3, 11.1 and 11.2 and Xcode wasn't able to figure out which version to use for the Command Line Tools and left the dropdown with empty. Once 11.1 was selected for my purpose, git commands started to work. – Chandana Kithalagama Nov 18 '19 at 23:34
  • This popup is equivalent to calling `xcode-select --switch` with the path to the Xcode package of whatever version you select here, by the way. – uliwitness Feb 15 '20 at 10:55
  • Good hint thank you , Whatever the way , the important thing is to solve the issue – taha Apr 06 '20 at 13:54
  • This works for me.. Thanks a lot. I was having old and new version of Xcode at different locations. – iGW Apr 13 '20 at 10:35
  • downvoted: you must understand the installing xcode is what is the worst option. Why should we be forced to installe 600MB of xcode just to enable the path of an already installed git? – Lazarus Thurston Jan 05 '23 at 11:48
52

I've used xcode-select --install given in the accepted answer in previous major releases.

I've just upgraded to OS X 10.15 Catalina and run the Software Update tool from preferences again after the OS upgrade completed. The Xcode utilities update was available there, which also sorted the issue using git which had just output xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools)

Ryan Stewart
  • 651
  • 6
  • 5
  • If you have Xcode installed, you **do not need the separate command line tools install**. Just make sure you run `xcode-select --switch /Applications/Xcode.app/Contents/Developer` or `xcode-select --reset` so Terminal will use the command line tools inside Xcode instead of the ones installed by the "command line tools" standalone installer. From then on, the App Store will auto-update Xcode and your tools will stay current. – uliwitness Feb 15 '20 at 10:52
46

I figured out the Xcode Command Line Tools part from the error message, but after running Xcode and getting the prompt to install the additional tools it did claim to install them, but still I got the same error after opening a new terminal.

So I did the xcode-select --install manually and after that it worked for me.

Cœur
  • 37,241
  • 25
  • 195
  • 267
P. Hurme
  • 469
  • 3
  • 2
  • 4
    If you have Xcode installed, you **do not need the separate command line tools install**. Just make sure you run `xcode-select --switch /Applications/Xcode.app/Contents/Developer` or `xcode-select --reset` so Terminal will use the command line tools inside Xcode instead of the ones installed by the "command line tools" standalone installer. From then on, the App Store will auto-update Xcode and your tools will stay current. – uliwitness Feb 15 '20 at 10:53
43

Mac OS : Big Sur

First Priority

sudo xcode-select --reset

sudo xcodebuild -license

Second Priority

xcode-select --install
Anand Khanpara
  • 846
  • 8
  • 8
  • 5
    Best answer for Big Sur – Ling Vu Dec 07 '20 at 12:46
  • 2
    For big Sur, this first priority is usefull. Thanks for saving lot of time and Data. – Manish Dec 14 '20 at 09:15
  • 2
    I am using Big Sur (xcode-select --install) helped me. – Ali Qaderi Dec 15 '20 at 07:00
  • Work for me on catalina – Romain TAILLANDIER Mar 04 '21 at 13:06
  • best answer! This issue doesn’t require installation of the tool again – MMK Mar 31 '21 at 16:36
  • According to the XCode man pages(Yea they do have documentation!!!) ``` -r, --reset Unsets any user-specified developer directory, so that the developer directory will be found via the default search mecha- nism. This command must be run with superuser permissions (see sudo(8)), and will affect all users on the system. ``` – AnandShiva May 12 '21 at 14:50
  • Thanks - worked for me! Why do MacOS upgrades always break dev tools? Disincentivizes upgrading since this is my dev laptop. – newbie Jul 06 '21 at 22:04
  • Thanks - worked for me! Why do MacOS upgrades always break dev tools? Disincentivizes upgrading since this is my dev laptop. – newbie Jul 06 '21 at 22:04
  • Getting below error on BigSur ➜ ~ sudo xcodebuild -license dyld: dyld cache load error: existing shared cache in memory is not compatible dyld: Library not loaded: /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation Referenced from: /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild Reason: image not found xcrun: error: unable to locate xcodebuild, please make sure the path to the Xcode folder is set correctly! xcrun: error: You can set the path to the Xcode folder using /usr/bin/xcode-select -switch – Purushotham Kumar Aug 27 '21 at 07:37
35

Following worked on M1

ProductName:    macOS
ProductVersion: 11.2.1
BuildVersion:   20D74

% xcode-select --install

Agree the Terms and Conditions prompt, it will return following message on success.

% xcode-select: note: install requested for command line developer tools
ras
  • 618
  • 8
  • 15
33

If you have Xcode downloaded manually (i.e. not from the App Store) or don't have Xcode at all:

  1. sudo rm -rf /Library/Developer/CommandLineTools
  2. Go to https://developer.apple.com/download/more/ to download Command Line Tools (macOS 10.14) for Xcode 10
  3. Setup Command Line Tools

If you have Xcode installed from the App Store:

  1. xcode-select --install
Şafak Gezer
  • 3,928
  • 3
  • 47
  • 49
Melih Sevim
  • 930
  • 6
  • 9
  • 2
    I want to install Command Line Tools only and Not Xcode. This solution seems to be the best. Minimal install – mythicalcoder Jul 18 '19 at 17:34
  • 2
    Perfect for me since I don't need Xcode but I do need Git :) – Ryan Amaral Jan 22 '20 at 12:37
  • After I installed Catalina and trying the `xcode-select --install` answer I had an error from the UI installer: "xcode-select: note: install requested for command line developer tools". This was the only thing that worked for me since I didn't want to install Xcode. (I used the Command Line Tools for XCode 12.) – vincentmajor Sep 27 '20 at 21:11
30

Open Terminal:

install XCode developer tools and fix the problem.

$ xcode-select --install

Reset the path to Xcode if you have several versions:

$ xcode-select --switch /Applications/Xcode.app
$ xcode-select --switch /Library/Developer/CommandLineTools
Selim Reza
  • 683
  • 1
  • 11
  • 31
  • 2
    If you have Xcode installed, you **do not need the separate command line tools install**. Just make sure you run `xcode-select --switch /Applications/Xcode.app/Contents/Developer` or `xcode-select --reset` so Terminal will use the command line tools inside Xcode instead of the ones installed by the "command line tools" standalone installer. From then on, the App Store will auto-update Xcode and your tools will stay current. – uliwitness Feb 15 '20 at 10:56
  • 2
    Also, it makes no sense to do both calls to `xcode-select --switch` above. The second one overwrites what the first one did. Do the first one and your command line tools will update as part of Xcode. – uliwitness Feb 15 '20 at 10:57
26
  1. Run this command:

xcode-select --install

  1. Hit return for a progress indicator on the Command Line Tools download.

  2. After installation of the Command Line Tools has been completed, your Mac should be rebooted. If you’re getting “xcrun error invalid active developer path” while working in Terminal, refresh the application or relaunch it.

Even after following the above-mentioned steps, if you see the error: invalid active developer path (/Library/Developer/CommandLineTools). The next step would be to try and install Command Line Tools using a DMG file that can be downloaded directly from the Apple website.

Again, if you are using Homebrew, you need to update it. You don’t need to uninstall and again install Homebrew on Mac.

NOTE: If you are using Homebrew, try updating it after re-installing Command Line tools.

Credits: Git not working after macOS Update

Vaibhav Gupta
  • 501
  • 6
  • 4
14

This just happened to me after upgrading my Macbook pro to macOS Ventura. After the upgrade, the git command line stopped working with showing up this message.

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

Running brew upgrade fixed git command line.

sergeyan
  • 1,173
  • 1
  • 14
  • 28
12

As of September 13, 2022, I had a similar issue after upgrading my MBP M1 to Monterey 12.6, and although I followed some of the answers, my Mac kept prompting me with a dialogue to install git as a developer tool. Every time that the installation was completed, I was prompted to the same dialogue.

Finally, I had to do a combination of all the answers to make it work:

  1. First remove the command line tool:
sudo rm -rf /Library/Developer/CommandLineTools
  1. Reinstall the xcode-select:
xcode-select --install

The above will prompt you with a dialogue to confirm the installation.

  1. Set path to the Xcode folder with following:
sudo xcode-select -switch /Library/Developer/CommandLineTools
Amirsalar
  • 648
  • 9
  • 18
10

I observed in the Catalina privacy setting if Xcode not added in Full access disk I will get the same error, Xcode does not run scripts. Add your Xcode the same as in the attached image. After that clean build and run. Hope so it will work. Security & Privacy

Muhammad Shauket
  • 2,643
  • 19
  • 40
9

For me, I didn't have xcode installed (on Mojave OS). I went to the App Store on my mac and downloaded it, then went back to terminal and typed git and hit enter, then it worked.

kiko carisse
  • 1,634
  • 19
  • 21
9

I found that my version of Xcode was too outdated and installing command-line-tools wasn't helping. Here's what I did:

  • I completely uninstalled the outdated XCode
  • I reinstalled the most recent XCode from the app store
  • That was all. Git was restored.
muru
  • 4,723
  • 1
  • 34
  • 78
Caleb Mbakwe
  • 178
  • 1
  • 6
8

This works for me

sudo xcode-select --reset 
sudo xcodebuild -license

X-code must be installed.

Daniel Ale
  • 81
  • 1
  • 2
8

For me, for the macos Ventura 13.0 user installing this software helped enter image description here

I wasn't able to run any xcode install commands, git was not working at all.

You can find this package here https://developer.apple.com/download/all/

Freestyle09
  • 4,894
  • 8
  • 52
  • 83
6

For those using Catalina and Xcode-beta:

sudo xcode-select -s /Applications/Xcode-beta.app/Contents/Developer
Destry
  • 111
  • 2
  • 5
5

I updated my macOS yesterday,from macOS Mojave(10.14.6)to macOS Catalina(10.15.7),I was executing "git" command in my project. I get same errors。

run:

xcode-select --install
Jason
  • 145
  • 2
  • 3
5

After Updating macOS to Monterey (12.3) from BigSur getting such issue

only worked-

xcode-select --install

Done!

Ranjan Fadia
  • 1,363
  • 1
  • 14
  • 18
5

With previous app development experience, may I say with confidence that the git version delivered with apple always create problems. So the sooner you get rid of apple git the better, so may I suggest:

brew uninstall git
brew update
brew install git

# which git
/usr/local/bin/git
Yuqiu G.
  • 348
  • 4
  • 7
  • I think you might have the right idea bud. I ran into issues twice. Idk why I need a full development suite just to have git. – dustbuster Sep 15 '22 at 00:04
4

For me It happened after Mac OS update to Mojave and git was not functioning in Intellij

Solution:- Go to Settings, then File | Settings | Version Control | Git and edit Path to Git executable field which is /usr/local/bin/git

hitesh
  • 378
  • 4
  • 12
4

I had the same issue and couldn't use SVN after the update,

Just in case if doing xcode-select --install didn't fix the issue,

You might see,

svn: error: The subversion command line tools are no longer provided by Xcode.

Refer : https://developer.apple.com/documentation/macos_release_notes/macos_catalina_10_15_release_notes

Try installing the svn by brew

brew install svn

This should get you going.

prime
  • 14,464
  • 14
  • 99
  • 131
3

MacOS :Monterey
Year: 2022

Solution: Upgrade to 12.2.1 or later

I upgraded to Monetery 12.2 as my Macbook pro got replaced. Ran into same issue as OP:

Git is not working after macOS Update (Xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools)

One would think that by this time Apple would have added xCode & developer tools into OS main build. Turned out they did. I had to upgrade to 12.2.1, which included "command line tools for xCode".
I still need to do step upgrade to 12.4 , but I believe we finally have these tools as part of OS build.

Here's screen-shot while attempting to upgrade from 12.2.1 to 12.3.1 (I forgot to take one while upgrading from 12.2 to 12.2.1, but I am pretty sure it had same Addons)

enter image description here

Anil_M
  • 10,893
  • 6
  • 47
  • 74
3

For Ventura 13.0.1.

Update for macOS Ventura 13.0.1 (Nov 2022) Install Command Line Tools for Xcode 14.1

it's worked for me

Hossain Misho
  • 121
  • 1
  • 2
  • Came here after installing Ventura caused this issue. This worked for me too – Nicole Suter Dec 02 '22 at 19:41
  • You should not just link to solutions. You can provide the link as reference but you should actually explicitly include the solution in your answer on Stackoverflow. – wuliwong Dec 03 '22 at 16:15
2

None of the above answers worked for me. I had a couple of issues. First, I installed the latest version of Xcode, 14.0 beta. That ended up not working because it was a version that is not compatible with Monterey. And my computer is too old to install Ventura beta. So I had to go and find out which version of Xcode actually did work. And that ended up being 13.4.1. So I installed that. I had taken all the right steps beforehand to delete the old version, and then placed the new one, as always, into my Applications folder. But for whatever reason, it did not end up there. When I checked to see if my install was successful, errors were thrown in Terminal. I had also previously updated CLT, which included the correct version. However, Terminal returned that I needed to install CLT. And when I tried, it told me that it was already installed, but I should change the path of my Xcode or install CLT (which obviously was not a real option). I found the solution in this article entitled Xcode-select active developer directory error. And I ran the following command in Terminal which fixed my path:

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

Hope this helps anyone else who encounters the same issue when trying to update Xcode on macOS Monterey and also can't update to macOS Ventura.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Maria Campbell
  • 418
  • 5
  • 9
2

I am using Ventura 13.3.1 and an intel chip macbook pro and ran this code:

xcode-select --install

This code worked for me from Iterm2 but I had to run the code twice and go thru the install twice.

It was a good option for me as it avoids installing all of xcode and just the command line tools.

It took about 5 minutes with the crappy coffee shop wifi!

1

If you created a new Applications folder in an external drive and installed Xcode there:

sudo xcode-select --switch /Volumes/MyExternalStorageName/Applications/Xcode.app/Contents/Developer
Bagata
  • 2,120
  • 4
  • 25
  • 39
1

Edge case, but still worth writing down: when migrating from and older Mac with Migration Assistant, you may have selected the option to transfer all your applications from your older Mac. Applications, like Xcode needs to be updated if it was transferred and preserved OR delete from your other user's Applications folder. This is because Xcode has not been set up properly after the first start with the new OS version.

1

I had this same issue after updating to macOS 13 Ventura.

Command: xcode-select also does not seem work. so does sudo xcodebuild.

After checking the xcode itself it install the command line tools and the said command still fails to work.

enter image description here

After checking this part it appears to be blank. I just manually set it to use the available command line from the installed xcode and everything now works including git.

eNeF
  • 3,241
  • 2
  • 18
  • 41
  • related stuff. https://stackoverflow.com/questions/17980759/xcode-select-active-developer-directory-error so it is probably the order I did things that failed the commands. – eNeF Oct 26 '22 at 02:38
1

For macOS v13.1 (Ventura)

I updated from macOS v11 (Big Sur) to Ventura 13.1 (January 2023). I only installed Xcode on the App Store, and it worked for me.

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Abandev
  • 95
  • 1
  • 1
  • 14
0

Answer for "Macos Ventura"

Update the xcode from App Store then run:

sudo xcode-select --reset

Explanation

First, updated the xcode from App Store.

Make sure it is pointing to the correct location. Go to "xcode > Settings > locations" :

enter image description here

Then check the path of "active developer director". To check, run:

$ xcode-select -p
/Library/Developer/CommandLineTools

It is pointing to separately installed command line tools, which is incorrect because we already have xcode installed. It should point to Applications folder where the xcode is installed. To do that, run:

$ sudo xcode-select --reset

Now it must have reset the path, confirm it by running:

$ xcode-select -p
/Applications/Xcode.app/Contents/Developer

Just in case the reset doesn't fix the issue. Explicitly set the path:

$ sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
Shaharyar
  • 12,254
  • 4
  • 46
  • 66