ChatGPT解决这个技术问题 Extra ChatGPT

xcode-select active developer directory error

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?

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

N
Naman

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:

Install Xcode (get it from https://appstore.com/mac/apple/xcode) if you don't have it yet. Accept the Terms and Conditions. Ensure Xcode app is in the /Applications directory (NOT /Users/{user}/Applications). 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


@qodeninja Then replace /Applications/Xcode5-DP4.app with the proper path, I would assume.
@MaxNanasy i mean that's obvious. But no that didnt work. I had to uninstall and reinstall xcode for it to work again
I didn't need to do step 2. Installing Xcode was sufficient. :)
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!
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: stackoverflow.com/a/40819686/9636
I
Indamix

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

Install Command Line Tools (if you haven't already): xcode-select --install Change the active directory: sudo xcode-select -switch /Library/Developer/CommandLineTools

This worked for me (git).


I prefer this solution to installing Xcode, however it looks like you can't download xcode-select from Apple any longer: cl.ly/image/2T0u2f2D471a/content
I think I already have Command Line Tools installed, however, so this will not fix anything.
So, is the only way to get a usable xcodebuild to install the whole of Xcode? :-(
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.
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.
j
jay.tech66

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.


Fixed Robo VM setup.
THIS is the good answer and should be followed first. All the others suggesting to use sudo and even entering root mode is just bad practice
Fixed Ionic Capacitor
It saves my time! This works perfectly and easily! thanks
s
shim

Xcode > Preferences > Locations > Command Line Tools

https://i.stack.imgur.com/QUMTf.png

Select the option matching your version of Xcode.


Click on the link and look at the image. The solution to this problem is not complicated.
I have installed 8 xcode versions thats making and issue but the above one will resolve mine issue. You are a life saver ;)
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"!
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.
If you're wondering what to do, just click the "Command Line Tools" dropdown and select an option from what you see.
c
chunkyguy

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.

wonder what will happen if i uninstalled xcode and followed the steps above since i installed CLI after xcode. Would that messup my existing IOS app projects?
This worked for me on osx 10.14.4 with xcode 11.3.1
Worked after Big Sur upgrade (11.6).
E
Edor Linus

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

sudo xcode-select --reset

This is the same solution as in this other answer.
k
kometen

Type this in your terminal

xcode-select --install
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -license accept

Super cool! After these three commands execution finished, do remember to restart your terminal to apply the new changes.
A
Andrey Deineko

Just in case you're using xcode beta:

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

H
Hamoonist

I had to run this first

sudo xcode-select --reset

then

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

and then it worked.


For me the problem was fixed after running the first command. Running the second command broke things again. So just the first one (in my case). Thank you.
I second that, just running the --reset fixed the problem
This worked for me too . Thanks !!
R
Rahul Shenoy

Download Xcode from App Store. Go to Xcode preferences/Locations/CommandlineTools You just have to set it to the Xcode version. It automatically points to '/Application/Xcode.app'


M
Madbreaks

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

npm explore npm -g -- npm install node-gyp@latest

This worked for me, except I simply reinstalled with npm -g install node-gyp@latest
N
Nikhil Maheshwari

Please follow the steps below :

The latest version of Xcode can be downloaded from https://developer.apple.com/xcode/download/ 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 Now unlike other downloaded applications, on extraction, Xcode doesn't give the option to move it to Applications Note the XCODE-ACTUAL-LOCATION or move it to the Applications 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

2020, Xcode this works for me. Thank you. Please read carefully.
s
sandeepkohli

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!


j
javamonk

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

  #!/bin/bash
  exit 0

chmod +x /usr/local/bin/xcodebuild


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?
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.
n
nyedidikeke

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

J
JBis

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

From here:

$ cd /usr/bin $ sudo mv xcodebuild xcodebuild.orig (A backup just in case) $ vim xcodebuild Paste the following:

#!/bin/bash
if [[ $1 == '-version' ]]; then
  echo "Xcode 10.2.1"
  echo "Build version 10E1001"
else
  /usr/bin/xcodebuild.bak $@
fi

$ sudo chmod +x xcodebuild


Nice answer. Also appreciate you referencing the original source. :)
t
turibbio

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

Pay attention to the "\" to escape the space


b
bummi

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:

"xcode-select --print-path" is equal to "/Applications/Xcode.app/Contents/Developer" "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform" exists "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


C
Community

For context, today is Jan 28, 2019.

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

Run the following command in your terminal: sudo xcode-select --install 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.


S
Semir Hodzic

Simple reinstall xcode-select

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

A
Abdullah Aden

Manually installing Command LineTool worked for me.

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

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


L
Languoguang
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.


J
Jaeseok An

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.


l
legel

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.


M
Mark Richman

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:

https://i.stack.imgur.com/b8keP.png

That's it!


S
Sweet Chilly Philly

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.


B
Binary_Hits00

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

Open XCode

Go To Xcode > Preferences > Locations

From the Command Line Tools Select your XCode