309

I'm having Xcode issues when I try to use Homebrew and Git:

xcrun: error: active developer path ("/Applications/Xcode.app/Contents/Developer") does not exist, use xcode-select --switch path/to/Xcode.app to specify the Xcode that you wish to use for command line developer tools (or see man xcode-select)

I can type xcode-select and it shows that the command exists. When I type xcode-select -p it shows:

/Applications/Xcode.app/Contents/Developer

but when I do which xcode-select, it gives me:

/usr/bin/xcode-select

I've tried to use the command switch and install again via the Apple Developer site, but none of these options have worked so far... How can I fix this?

13 Answers 13

879

I tried that, and it didn't work, but I found the answer. I just had to reset the developer's path:

sudo xcode-select --reset

Now everything is normal.

7
  • 6
    --reset normally this must be run as root Commented Feb 14, 2017 at 20:09
  • 48
    Thanks. I had uninstalled xcode and installed just the command line tools because I didn't need the whole xcode package on my mac with limited space. However, I was still unable to use commands such as gcc, but after running this command, it works like a charm Commented Jun 22, 2017 at 15:38
  • 1
    I just tried it; now I'm getting "SDK "macosx" cannot be located" lol
    – Jozey
    Commented Dec 28, 2017 at 21:02
  • 3
    --reset works well for me. I need only the xcode cli for php development. So I decided to remove the complete xcode from my mac, then I downloaded only the xcode CLI installer(about 170MB). After I upgrade the installed xcode CLI via app store, and applied sudo xcode-select --reset, I am able to use brewand other command line tools such as git like before. Thanks.
    – vikbert
    Commented Feb 1, 2018 at 11:38
  • 2
    Is there any danger in using --reset? Commented Jun 2, 2019 at 21:48
235

In my case, I had uninstalled Xcode and then issues with Git CLI started. I solved the problem running the following commands:

sudo xcode-select -r
sudo xcode-select --switch /Library/Developer/CommandLineTools

And then validating a new path with:

sudo xcode-select -p
4
  • 4
    Worked for me after uninstalling xcode, saved my day
    – Ilan Levy
    Commented Apr 24, 2020 at 17:09
  • 1
    I was facing issues on Android Studio after I uninstalled XCode. Worked for me. I also had to restart Android Studio after using these commands. Commented Jul 31, 2020 at 8:37
  • This works for me after having issue with node-gyp on macOS Catalina
    – Seno
    Commented Apr 30, 2021 at 8:19
  • i got message can't install the software. with the command i got xcode-select: error: invalid developer directory '/Library/Developer/CommandLineTools' Commented Feb 19, 2023 at 15:04
228

Mostly this error occurs when you have installed a newer version of Xcode. And the command line tools are yet to be initialized.

To resolve this: Go under Xcode PreferencesLocations (tab) → And the bottom options is Command Line Tools. Please select the Xcode version for tools.

Example (for Xcode 10.0 (10A255)): Go under Xcode PreferencesLocations (tab) → And the bottom options is Command Line Tools. Select Xcode 10.0 (10A255).

For more details, please see this image:

Select Command Line Tools

4
  • I already see it as shown in the above image, but I still see the same error on my setup. I even tried resetting. Any idea? I
    – Yoku
    Commented Nov 12, 2018 at 13:29
  • 6
    To do this programmatically (I had the error because I uninstalled Xcode), sudo xcode-select --switch /Library/Developer/CommandLineTools (needs to be run as root)
    – hbrannan
    Commented Apr 15, 2019 at 17:32
  • I had to restart my IDE after I did this and then it worked.
    – ponder275
    Commented Oct 11, 2021 at 14:41
  • The comment above is what fixed it for me Commented Dec 14, 2022 at 22:06
82

I have faced the same issue as I have uninstalled the Xcode abruptly. Running the below command (from Terminal) helped me to resolve this.

sudo xcode-select -switch /
2
  • Check this link also if you have any other error. github.com/Homebrew/legacy-homebrew/issues/23500 Commented Jul 27, 2019 at 7:28
  • 3
    This worked for me. The problem was I uninstalled xcode in my mac. The command line is somehow still tied to xcode. So I went to ~library/Developer and deleted all folders and ran this command.
    – santosh
    Commented Feb 26, 2020 at 7:56
48

This error is coming because Xcode gets deleted, corrupt or moved. In my case I removed Xcode from my Mac and faced the same issue.

I fixed it by executing two simple steps:

  1. Open Terminal

  2. Simply run the following command

    sudo xcode-select -r
    

And now the error has been resolved.

3
  • 2
    It works for MacOS 12.4
    – vanduc1102
    Commented Jun 11, 2022 at 12:31
  • 1
    This worked for me. I tried deleting XCode and reinstalling it, and gotxcrun: error: active developer path ("/Applications/Xcode.app/Contents/Developer") does not exist.
    – B Seven
    Commented Oct 30, 2022 at 20:04
  • 1
    Thank you for showing remove That ...... app from that ....... OSx Commented Dec 8, 2022 at 22:13
36

Use this:

sudo xcode-select -switch /

This should solve the problem.

2
19

Do what the error suggests. Try that:

xcode-select --switch /Applications/Xcode.app

That should do the trick.

1
  • 3
    --switch must be run as root
    – Sid
    Commented Apr 3, 2018 at 11:13
7

For me it helps to install Xcode CLI,

xcode-select --install

after uninstalling Xcode (I don't develop for the OS X or iOS).

Then I could successfully build the downloaded source with make.

0
3

Try the error suggestion:

sudo xcode-select --switch /Applications/Xcode.app

And then test the Git executable path.

Enter image description here

2

In my case such error occurred after I has tried to symbolicate crash report, and according to a manual, entered command export DEVELOPER_DIR=”/Applications/Xcode.app/Contents/Developer”

I tried some proposed here solutions but nothing helped.

Then I realized that I have added an environment variable DEVELOPER_DIR to my terminal and this led to error: "xcrun: error: missing DEVELOPER_DIR path:"

Then I've just reboot my terminal, that cleaned the environment variable and the error disappeared.

(FYI: environment variables may be checked with printenv command in terminal)

0
2

I had the same problem and had to remove Developer tools completely, and reinstall:

rm -rf /Library/Developer/CommandLineTools
xcode-select --install

Tip: because Xcode had been improperly uninstalled, I had to manually (re)move the Xcode app, too:

mv /Applications/Xcode.app/ /Applications/Xcode.app.bak
1
  • The installation of the xcode gui app definitely was part of the issue for me. I got rid of it and re-installed xcode-select from scratch and everything started working.
    – Loopy
    Commented Dec 30, 2022 at 16:01
1

Use this command:

sudo xcode-select --switch /Applications/Xcode.app

Check this out

3
  • sudo xcode-select --switch /Applications/Xcode.app (space before --) - did not work anyway Commented Apr 25, 2023 at 12:22
  • Works as expected, sudo xcode-select --switch path/to/Xcode.app is also written in the XCode errors report. Commented Sep 5, 2023 at 10:32
  • Please review Why not upload images of code/errors when asking a question? (e.g., "Images should only be used to illustrate problems that can't be made clear in any other way, such as to provide screenshots of a user interface.") and do the right thing (it covers answers as well, including textual output). Thanks in advance. Commented Oct 17, 2023 at 3:22
0

For my MacBook Pro M1 Apple silicon for the case, I already tried all the previous answers and it was not solved.

I have solved it by the discussion in Unable to install Xcode command line developer tools.

There is have two options to solve, in my case...

  1. I have uninstalled Xcode, because I don't need it again
  2. install standalone mode, but it doesn’t work: "can't install the software"
  3. It was solved by trying to download it manually by command line tools. Check on the discussion thread for the link file (741.5 MB).

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