MacOS – ERROR: ‘xcodebuild’ requires Xcode

catalinamacosxcode

OBSERVATIONS

I was not expecting the command to return an error:

/usr/bin/xcodebuild -version (Reference) returns an error:

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

ls -l /usr/bin/xcodebuild returns:

-rwxr-xr-x 1 root wheel 31488 May 27 19:37 /usr/bin/xcodebuild

xcodebuild -version returns:

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

gcc --version returns:

Configured with:
–prefix=/Library/Developer/CommandLineTools/usr –with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.3 (clang-1103.0.32.62) Target:
x86_64-apple-darwin19.5.0 Thread model: posix InstalledDir:
/Library/Developer/CommandLineTools/usr/bin

QUESTIONS

Why is the an error returned in the first observation and what remedies are available?

How can I test (without installing anything to determine if I have the problem described here?

I am concerned that changing the active directory

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

will cause problems with brew or other installed apps. Though it would seem that my active directory and the suggested change is the same.

UPDATES

$ ls -l /Applications/
total 0
drwxr-xr-x  4 user  admin  128 Jul 26 00:06 Polyspace
drwxr-xr-x@ 3 root  wheel   96 Apr 23 00:52 Safari.app
drwxr-xr-x@ 3 user  staff   96 Sep 30  2019 Sublime Text.app
drwxr-xr-x@ 3 user  staff   96 May 15 20:06 Transmission.app
drwxr-xr-x  4 root  wheel  128 May 27 19:31 Utilities
$ ls /usr/bin | grep -I Xcode
xcode-select
xcodebuild

Best Answer

Assuming your Xcode.app is installed in /Applications you can just run

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

to fix this.