975

Saw the following error when running an npm install which required node-gyp... but could be triggered by anything which requires xcode-select.

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

What is the problem?

Or A.
  • 1,220
  • 1
  • 15
  • 28
tjmehta
  • 28,667
  • 4
  • 21
  • 18
  • 3
    a blunt force alternative would be just to uninstall it and reinstall it again. out of all these answers that is the only thing that worked for me – qodeninja Nov 01 '13 at 17:27
  • @qodeninja reinstall did not work for me –  Aug 14 '22 at 03:32

30 Answers30

1881

This problem happens when xcode-select developer directory was pointing to /Library/Developer/CommandLineTools when a full regular Xcode was required (happens when CommandLineTools are installed after Xcode)

Solution:

  1. Install Xcode (get it from https://appstore.com/mac/apple/xcode) if you don't have it yet.
  2. Accept the Terms and Conditions.
  3. Ensure Xcode app is in the /Applications directory (NOT /Users/{user}/Applications).
  4. Point xcode-select to the Xcode app Developer directory using the following command:
    sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

Note: Make sure your Xcode app path is correct.

  • Xcode: /Applications/Xcode.app/Contents/Developer
  • Xcode-beta: /Applications/Xcode-beta.app/Contents/Developer
Naman
  • 27,789
  • 26
  • 218
  • 353
tjmehta
  • 28,667
  • 4
  • 21
  • 18
  • @qodeninja Then replace `/Applications/Xcode5-DP4.app` with the proper path, I would assume. – Max Nanasy Nov 01 '13 at 10:39
  • @MaxNanasy i mean that's obvious. But no that didnt work. I had to uninstall and reinstall xcode for it to work again – qodeninja Nov 01 '13 at 17:26
  • I've been bitten by this a couple of times, generally when using cocos2dx. It happens if you have alternate versions of XCode, or have some other nonstandard installation. Basically the path to pass to xcode-select should be one that contains your XCode binaries at a subpath /usr/bin. If that exists, is your argument to xcode-select. – Echelon May 15 '14 at 06:41
  • Works for YOSEMITE too – tjmehta Jan 09 '15 at 19:41
  • How to install xcodebuild without full Xcode (which takes 2.49 GB...): http://stackoverflow.com/questions/8417137/xcodebuild-command-tool-without-installing-xcode-itself – Magne Mar 06 '15 at 09:10
  • For the Xcode 7 beta that runs on OS X 10.10, use `sudo xcode-select -s /Applications/Xcode-beta.app/Contents/Developer`. – alwillis Jun 21 '15 at 22:57
  • Thanks man. It works. But when we execute the sudo code we should make sure that xcode app name is matched with the exact xcode app name. if you have renamed xcode as xcode_7 then when u execute the sudo u have to give xcode_7 in the sudo, because it will search for that stuff. Hope someone will save their time:) – Vijay-Apple-Dev.blogspot.com Jan 07 '16 at 08:08
  • So, when you install a new version of Xcode (I do mine by hand and give them different names), you need to change this link. Or have a common name and a symlink? – Chris Prince Jun 24 '16 at 19:15
  • 1
    I didn't need to do step 2. Installing Xcode was sufficient. :) – Ryan Heathcote Oct 14 '16 at 20:45
  • 27
    **macOS High Sierra 10.13**, I already had Xcode 9.2 installed and faced the same issue after installing **carthage**. Just did the step 4 and that's it! – RAM237 Mar 22 '18 at 08:30
  • @tjmehta THANK YOU! YOU'RE A LIFE SAVER (no, didn't forgot my caps on) – Caius Apr 13 '18 at 18:03
  • Both yours and @FranklinA answers worked for me. Writing this at 17-dec-18 – jegadeesh Dec 17 '18 at 08:04
  • I already had xcode installed, but I was getting this error. Step 4 from this answer was all that was required to fix it. – HappyDog Mar 07 '19 at 14:24
  • 1
    On a new Mojave `10.14.5` install, I installed Command Line Tools 10.2.1 and then Xcode 10.2.1, and got the above error. Then, I tried using this solution, and I still got the above error. `Franklin A`'s solution worked: https://stackoverflow.com/a/40819686/9636 – Heath Borders Jul 22 '19 at 15:27
  • it works fine on **Catalina** but I needed to add `--unsafe-perm=true` option while using `npm install` – Ahmed Wahba Feb 12 '20 at 08:35
  • All I needed was sudo xcode-select -s /Applications/Xcode.app/ which correctly set the directory. xcode-select --print-path then returned "/Applications/Xcode.app/Contents/Developer" and Xcode command line tools started working, e.g. open -h NSArray.h started opening the correct header file, rather than triggering a complaint about my DEVELOPER_DIR. – w0mbat Feb 28 '20 at 22:24
  • This solution fixed this same error message when trying to do `pip install salt` on OS X 10.15.4 (Catalina). Python version 3.8.2, in case it matters. – Luke Sheppard May 07 '20 at 16:59
  • To help with SEO (since this solved my problem), this will also fix an issue with SwiftLint running when you get the following error `illegal hardware instruction swiftlint rules`. Thanks! – Kyle Venn May 23 '20 at 20:29
  • This provided the missing piece of information I needed to fix my `xcode-select: error: invalid developer directory` issue (no squiggly in front of /Applications!). Thank you so much!!! – Kreidol Jul 23 '20 at 23:09
  • sudo xcode-select -s /Applications/Xcode.app/Contents/Developer working for me and fix my issue . Thanks – Ashish Dec 12 '21 at 11:50
  • Download the Xcode here. Otherwise, u would have to retry a couple of times. https://developer.apple.com/download/all/?q=xcode – Ananda Subasinghe Nov 25 '22 at 03:55
  • This worked for me: sudo xcode-select -s /Applications/Xcode.app/Contents/Developer – jcpennypincher Feb 14 '23 at 00:28
  • Amazing. was looking for this solution for long time. worked for me perfectly. – Shuhad zaman Feb 19 '23 at 07:53
  • How the hell does this happen? – Alper Feb 19 '23 at 20:36
221

I was having an issue while trying to install packages using npm. I got the error: "sudo xcode-select -s /Applications//Xcode.app/Contents/Developer/"

To fix this

  • I opened Xcode.
  • Preferences
  • Locations
  • Selected the Command Lin Tools: Xcode 6.1.1

Now when installing packages with npm I no longer get errors.

jay.tech66
  • 2,327
  • 1
  • 13
  • 6
217

Other solution for those who don't want to install Xcode:

  1. Install Command Line Tools (if you haven't already):

    xcode-select --install

  2. Change the active directory:

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

This worked for me (git).

Indamix
  • 2,485
  • 1
  • 18
  • 15
  • 1
    from all the solutions out there for mavericks, this was the only one working for me. – bitoiu Oct 23 '13 at 22:41
  • 26
    I prefer this solution to installing Xcode, however it looks like you can't download `xcode-select` from Apple any longer: http://cl.ly/image/2T0u2f2D471a/content –  Oct 25 '13 at 20:38
  • 10
    I think I already have Command Line Tools installed, however, so this will not fix anything. –  Oct 25 '13 at 21:33
  • 9
    So, is the only way to get a usable `xcodebuild` to install the whole of Xcode? :-( –  Oct 26 '13 at 10:52
  • 2
    Looking to get a better answer here, hopefully: http://stackoverflow.com/questions/19605862/unable-to-use-xcodebuild-on-mavericks-with-command-line-tools-installed –  Oct 26 '13 at 10:57
  • optionally, using [the installer](http://nodejs.org/download/) takes seconds and just works – mgamba Sep 04 '14 at 21:00
  • 74
    **This answer seems incorrect**. The whole point is that **'xcodebuild' requires Xcode**, i.e., a full install of Xcode, nor CommandLineTools. Testing it here, switching to CommandLineTools doesn't stop the error, nor would it. – mikemaccana Sep 10 '14 at 15:11
  • 27
    This answer is no longer correct. As of May 2015, when using Command Line Tools for OSX 10.10 (Yosemite), the xcodebuild command no longer functions without full xcode installed. – HipsterZipster May 15 '15 at 02:39
  • Yosemite 10.10.4, the second command has solved this issue (I had command tools but didn't have Xcode) – Evmorov Jul 26 '15 at 19:52
  • For me, `xcode-select --install` failed but then `sudo xcode-select -switch /Library/Developer/CommandLineTools` worked. – Adrian Lynch May 17 '16 at 16:37
  • This didn't work for me. It kept saying that Xcode was already installed. Installing from AppStore finally did it (tjmehta's answer). – lfk Jul 03 '18 at 07:29
  • MacOS High Sierra 10.13.6 sudo xcode-select -switch /Applications/Xcode6-Beta.app/Contents/Developer – Nditah Aug 23 '18 at 19:31
  • 1
    For anyone on a fresh install of mojave, I resolved this issue by installing the cli directly from https://developer.apple.com/download/more/ I dont know why apple cant find its own servers. – Salyangoz Oct 31 '18 at 17:06
  • On a new Mojave `10.14.5` install, I installed Command Line Tools 10.2.1 and then Xcode 10.2.1, and got the above error. Then, I tried using this solution, and I still got the above error. `Franklin A`'s solution worked: https://stackoverflow.com/a/40819686/9636 – Heath Borders Jul 22 '19 at 15:27
  • Worked for me in 2021, osx 11.6.1. First command said xcode-select was already installed, so ran the second one. It worked and then my original problem was also resolved. Saved me 12GB. – coblr Jan 25 '22 at 20:15
  • This worked for me on xcode 14.2. – Wallace B. McClure Feb 01 '23 at 14:26
205

Xcode > Preferences > Locations > Command Line Tools

screenshot

Select the option matching your version of Xcode.

shim
  • 9,289
  • 12
  • 69
  • 108
FranklinA
  • 2,151
  • 1
  • 8
  • 5
  • 1
    Click on the link and look at the image. The solution to this problem is not complicated. – FranklinA Nov 26 '16 at 15:10
  • I have installed 8 xcode versions thats making and issue but the above one will resolve mine issue. You are a life saver ;) – ahsan Oct 02 '18 at 06:43
  • This was the only thing that worked for me when I tried to have 2 version of XCode installed. Trying `xcode-select` kept saying "error: invalid developer directory"! – mc01 Oct 24 '18 at 20:46
  • 1
    This was the solution I needed. Not sure why that command Line Tools option wasn't set. But once I set it, it resolved my problem. Thanks. – jdavis Dec 14 '18 at 15:52
  • If you're wondering what to do, just click the "Command Line Tools" dropdown and select an option from what you see. – Deepak Joy Cheenath Jun 22 '21 at 16:06
79

Simply run sudo xcode-select -r which should automatically reset the path.

 -r, --reset
              Unsets any user-specified developer directory, so that the developer directory will be found via the default search mechanism. This command must  be
              run with superuser permissions (see sudo(8)), and will affect all users on the system.
chunkyguy
  • 3,509
  • 1
  • 29
  • 34
52

I just ran the following command and the issue was resolved for me:

sudo xcode-select --reset
Edor Linus
  • 826
  • 8
  • 9
34

Type this in your terminal

xcode-select --install
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -license accept
kometen
  • 6,536
  • 6
  • 41
  • 51
Dennis Liger
  • 1,488
  • 2
  • 13
  • 28
  • 1
    Super cool! After these three commands execution finished, do remember to restart your terminal to apply the new changes. – Johnny Jan 21 '21 at 02:23
26

if you installed XCode already, All you have to do is to...

  • Open XCode
  • Go To XcodePreferencesLocations
  • From the Command Line Tools Select your Xcode enter image description here
Alessio Cantarella
  • 5,077
  • 3
  • 27
  • 34
Binary_Hits00
  • 570
  • 6
  • 7
11

Just in case you're using xcode beta:

sudo xcode-select -s /Applications/Xcode-Beta.app/Contents/Developer
Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145
11

I had to run this first

sudo xcode-select --reset

then

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

and then it worked.

Hamoonist
  • 2,286
  • 3
  • 19
  • 36
8
  1. Download Xcode from App Store.

  2. Go to Xcode preferences/Locations/CommandlineTools

    You just have to set it to the Xcode version. It automatically points to '/Application/Xcode.app'

Rahul Shenoy
  • 737
  • 6
  • 10
5

I was having the same problem in high sierra. running the following command solved it

npm explore npm -g -- npm install node-gyp@latest
Madbreaks
  • 19,094
  • 7
  • 58
  • 72
Luja Shrestha
  • 2,727
  • 2
  • 23
  • 29
  • 1
    This worked for me, except I simply reinstalled with `npm -g install node-gyp@latest` – ty. Mar 04 '19 at 21:49
4

Simple reinstall xcode-select

sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
Semir Hodzic
  • 509
  • 6
  • 9
4

Please follow the steps below :

  1. The latest version of Xcode can be downloaded from https://developer.apple.com/xcode/download/
  2. It will be downloaded in the 'Downloads' unless specified otherwise. Please make sure to check the path where you have downloaded and extracted the Xcode
  3. Now unlike other downloaded applications, on extraction, Xcode doesn't give the option to move it to Applications
  4. Note the XCODE-ACTUAL-LOCATION or move it to the Applications
  5. Note if you have downloaded Xcode or Xcode-beta

Based on 4 and 5, execute one of the commands (Do not execute all of them without reading above description):

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
sudo xcode-select -s /Applications/Xcode-beta.app/Contents/Developer
sudo xcode-select -s /[XCODE-ACTUAL-LOCATION]/Xcode.app/Contents/Developer
sudo xcode-select -s /[XCODE-ACTUAL-LOCATION]/Xcode-beta.app/Contents/Developer
Nikhil Maheshwari
  • 2,198
  • 18
  • 25
3

Install Xcode from App Store. After installing run xcodebuild with root privileges i.e. sudo xcodebuild and accept the language. After this npm install bcrypt worked like a charm!

3

Without Xcode: create file /usr/local/bin/xcodebuild with content to cheat XcodeSelect

  #!/bin/bash
  exit 0

chmod +x /usr/local/bin/xcodebuild

javamonk
  • 180
  • 1
  • 7
  • I must say I'm having issues with node-gyp for some reason running `xcodebuild` when I only have CLT installed. I'd rather not install Xcode just to install some native extensions nothing to do with Mac and iOS development, so I'm very up for trying this technique to basically just shut the error up. Do you know if there are any repercussions of doing this? I can only imagine that node-gyp s calling `xcodebuild` for a reason, and by doing an `exit 0` we're breaking the toolchain for a given build, but I'm not sure, as I don't know why it'd be using `xcodebuild` in the first place. Any ideas? – alexrussell May 10 '16 at 09:33
  • 1
    I tried this, it made no difference unfortunately. I really don't want to install XCode - this is just some Apple marketing BS to force you to install it. – Alex Sep 11 '17 at 09:27
2

In case you are using Xcode beta, run

sudo xcode-select --switch /Applications/Xcode-beta.app/Contents/Developer 

instead of

sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
nyedidikeke
  • 6,899
  • 7
  • 44
  • 59
M.Sobhy
  • 21
  • 4
2

I was able to solve this error without installing the full Xcode application. You must, however, have xcode command line tools installed.

From here:

  1. $ cd /usr/bin
  2. $ sudo mv xcodebuild xcodebuild.orig (A backup just in case)
  3. $ vim xcodebuild
  4. Paste the following:
#!/bin/bash
if [[ $1 == '-version' ]]; then
  echo "Xcode 10.2.1"
  echo "Build version 10E1001"
else
  /usr/bin/xcodebuild.bak $@
fi
  1. $ sudo chmod +x xcodebuild
JBis
  • 827
  • 1
  • 10
  • 26
1

XCode2: sudo xcode-select -s /Applications/Xcode\ 2.app/Contents/Developer

Pay attention to the "\" to escape the space

turibbio
  • 41
  • 1
  • 2
  • 8
1

I had two instance of Xcode installed xcode.app and xcode-beta.app When I tried to create a build with netbeans it showed me the error "supported version of xcode and command line tools not found netbeans"

I followed the following steps:

  1. "xcode-select --print-path" is equal to "/Applications/Xcode.app/Contents/Developer"
  2. "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform" exists
  3. "xcodebuild -version" starts with "Xcode"

after 1 I found that it is pointing me to xcode-beta.app

so here is the solution which worked like a charm:

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

bummi
  • 27,123
  • 14
  • 62
  • 101
Shashank Saxena
  • 2,014
  • 17
  • 11
1

For context, today is Jan 28, 2019.

On my Mac, I did two things to resolve this problem:

  1. Run the following command in your terminal:
    sudo xcode-select --install

  2. Restart your Mac.

Until I restarted the computer, the problem kept occurring in my Android Studio. After reboot, it was working just fine. Also note that I did not execute any --switch commands as others are doing. I hope this helps.

Community
  • 1
  • 1
Steve
  • 325
  • 3
  • 6
1

Manually installing Command LineTool worked for me.

  1. I stalled xcode through App Store
  2. Still could not download Homebrew
  3. I installed Command Line Tool manually through link.
  4. Bing Bang Boom

https://developer.apple.com/download/more/?=command%20line%20tools

Abdullah Aden
  • 882
  • 9
  • 13
1

For those using a newer version of Xcode (I'm using 14.3), you need to install command Line tools. I suggest two ways.

  1. Either run this command on terminal:

    xcodebuild -runFirstLaunch xcode-select --install

  2. Or download the installable DMG file (command line tools for Xcode 14.3) from this link and install it.

I stumbled upon this issue when trying to install brew on macOS 13.3.

Alessio Cantarella
  • 5,077
  • 3
  • 27
  • 34
Amir Gorji
  • 2,809
  • 1
  • 21
  • 26
0
sudo xcode-select -s /Applications/Xcode 10.app/Contents/Developer

languoguangs-iMac:/ languoguang$ sudo xcode-select -s /Applications/Xcode 10.app/Contents/Developer
xcode-select: error: invalid argument '10.app/Contents/Developer'
Usage: xcode-select [options]

Print or change the path to the active developer directory. This directory
controls which tools are used for the Xcode command line tools (for example, 
xcodebuild) as well as the BSD development commands (such as cc and make).

Options:
  -h, --help                  print this help message and exit
  -p, --print-path            print the path of the active developer directory
  -s <path>, --switch <path>  set the path for the active developer directory
  --install                   open a dialog for installation of the command line developer tools
  -v, --version               print the xcode-select version
  -r, --reset                 reset to the default command line tools path
languoguangs-iMac:/ languoguang$ sudo xcode-select -s "/Applications/Xcode 10.app/Contents/Developer"

because my Xcode name in Application is "Xcode 10",

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

works.

Languoguang
  • 2,166
  • 2
  • 10
  • 15
0

In my case,

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

didn't work because my Xcode had some special name. eg) Xcode_11.2.0_beta_2_stackoverflow.app

cd /applications
ls

Then I found my Xcode name, then replace it with

sudo xcode-select -s /Applications/{myXcodeName}.app/Contents/Developer 

It worked for me.

Jaeseok An
  • 58
  • 6
0

None of the above worked for me. I originally installed Command Line Tools separately, and then all of Xcode. What worked for me was to uninstall Command Line Tools as shown here. Then, when trying to run xcode-select again, I was asked to reinstall them.

*By the way, the very reason why I found this thread was because I had installed some libraries (particularly gcc) with macports, presumably using the old Command Line Tools, and then I installed the full Xcode midway into development. So anyways, for my case, I had to reinstall macports after removing the stand-alone Command Line Tools, reinstalling them, reinstalling gcc, and then my compilation worked.

legel
  • 2,507
  • 3
  • 23
  • 22
0

There are only two steps required, and the full XCode.app is not required at all:

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

At this point the "Installing Softwre" dialog pops up:

enter image description here

That's it!

Mark Richman
  • 28,948
  • 25
  • 99
  • 159
0

None of the above solutions helped me. I was working on an old project, and I had the latest version of NodeJs installed globally (v14.x) on my computer.

No node version above 10.1.x worked for me and when testing I received the same error as above.

Solution

  • I installed "n" which is a nodeJs version manager like nvm
  • I downgraded my nodeJs version to 9.x
  • npm install now works.

I will now need to update my versions, or Specify my node version in my package.json.

Sweet Chilly Philly
  • 3,014
  • 2
  • 27
  • 37
0

The simple fix that worked for me is drag and drop Xcode.app from the current location (In my case it was in downloads) to Applications.

gandharv garg
  • 1,781
  • 12
  • 17
0

All I did which worked is run the command on the terminal:

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

Tashi
  • 477
  • 4
  • 12