Fixing "tool 'xcodebuild' requires Xcode" without installing Xcode

Short guide on how to fix frequent xcodebuild error

Warning

This post was written more than 5 years ago, and its contents may be out of date

Example of the error message

During some node.js stuff i’ve occured this error on packages build:

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

But in reality, Xcode is actually not always required to successfully build packages.

And here’s how to trick it:

In order to success, build process requires xcodebuild to return correct version information, so we just create a fake xcodebuild that return version and pass everything else to original file.

Step 1. cd /usr/bin

Step 2. Copy original xcodebuild: sudo mv xcodebuild xcodebuild.orig

Step 3. Create a fake xcodebuild:

Terminal window
sudo vim xcodebuild

Then paste this1:

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

Step 4. Make it executable: sudo chmod +x xcodebuild

Now you can install your packages!

Footnotes

  1. Source: https://randomfoo.net/2012/08/03/macports-without-xcode 🔗

Licensed under CC BY-NC 4.0

Comments