303

I'm having xcode issues when I try to use brew 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 Apple Developer site but none of these options have work so far... How can I fix this?

Tobi Nary
  • 4,566
  • 4
  • 30
  • 50
devB78
  • 11,894
  • 3
  • 14
  • 14

13 Answers13

860

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

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
devB78
  • 11,894
  • 3
  • 14
  • 14
  • 6
    --reset normally this must be run as root – Benja Garrido Feb 14 '17 at 20:09
  • 47
    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 – Anonymous Person Jun 22 '17 at 15:38
  • 1
    I just tried it; now I'm getting "SDK "macosx" cannot be located" lol – Hedylove Dec 28 '17 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 `brew`and other command line tools such as `git` like before. Thanks. – vikbert Feb 01 '18 at 11:38
  • 2
    Is there any danger in using --reset? – bananabanana Jun 02 '19 at 21:48
  • does not work ........ – mjs Apr 19 '22 at 21:09
  • definitely worked! – Erol Erdogan Mar 12 '23 at 13:51
231

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 new path with:

$ sudo xcode-select -p
starball
  • 20,030
  • 7
  • 43
  • 238
José Gil Ramírez
  • 2,521
  • 1
  • 13
  • 7
  • 4
    Worked for me after uninstalling xcode, saved my day – Ilan Levy Apr 24 '20 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. – Amey Bhandarkar Jul 31 '20 at 08:37
  • This works for me after [having issue with node-gyp on macOS Catalina](https://github.com/nodejs/node-gyp/blob/master/macOS_Catalina.md) – Seno Apr 30 '21 at 08:19
  • i got message can't install the software. with the command i got `xcode-select: error: invalid developer directory '/Library/Developer/CommandLineTools'` – Yogi Arif Widodo Feb 19 '23 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 Preferences > Locations (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 Preferences > Locations (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

starball
  • 20,030
  • 7
  • 43
  • 238
Harjot Singh
  • 6,767
  • 2
  • 38
  • 34
81

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 /
Bharath Kumar
  • 935
  • 7
  • 13
  • Check this link also if you have any other error. https://github.com/Homebrew/legacy-homebrew/issues/23500 – Narendra Solanki Jul 27 '19 at 07: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 Feb 26 '20 at 07:56
49

This error coming because xcode get deleted, corrupt or moved. In my case i removed xcode from my Mac and faced the same issue.

I fixed it by simple two steps

  1. Open Terminal
  2. Simply run following command
sudo xcode-select -r

And now error has resolved. Hope it will helpful.

Amit Kumar PRO
  • 1,222
  • 2
  • 15
  • 27
36

Use this:

sudo xcode-select -switch /

This should solve the problem.

bruceparker
  • 1,235
  • 1
  • 17
  • 33
19

How about what the error suggests? Did you try that?

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

That should do the trick.

Tobi Nary
  • 4,566
  • 4
  • 30
  • 50
7

For me it helps to install Xcode CLI xcode-select --install after uninstalling XCode (I don't develop for the OSx or iOS)

Then I could successfully build downloaded source with make

3

Try error suggestion :

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

And Then test Git Executable Path.

enter image description here

Mir Mahfuz
  • 663
  • 4
  • 9
2

I had the same problem and had to remove completely Developer tools, 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
Johann8
  • 649
  • 7
  • 20
  • 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 Dec 30 '22 at 16:01
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)

ViktoR
  • 691
  • 9
  • 11
0

for my mbp m1 apple sillicon for the case alr tried all the above answer and not solved.

i have solved by here discussion https://developer.apple.com/forums/thread/660641

there is have 2 option to solve, my case...

  1. i have uninstalled xcode because i don't need again
  2. install standalone mode, doesnt work. can't install the software
  3. solved by try download manual command line tools check on the discussion thread for the link file ( 741.5 MB ) .
Yogi Arif Widodo
  • 563
  • 6
  • 22
0

Use this command:

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

Check this out

Ayush Gupta
  • 1,057
  • 6
  • 11