Tim Hordern

I ♥ building amazing products and teams. QA + Product + DevOps + Fast = Awesome.

Making Xcodebuild Work With Node or Homebrew

Recently, I ran into an issue trying to get npm to install a new Node.js application that was similar to something that I’ve experienced before with Homebrew. Turns out trying to get Homebrew working correctly on OSX Mountain Lion is a bit of a pain. Both of these package managers rely on having Xcode installed and accessible at the command line.

Normally, you should be able to install Xcode and install the Developer Tools package, or just install the standalone Xcode Command Line Tools to allow command line applications to compile applications using Xcode. However, sometimes you’ll find that Xcode is no longer accessible from the command line.

This is the error I saw using npm:

1
2
3
Error: No developer directory found at /Developer. Run /usr/bin/xcode-select to update the developer directory path.

gyp: Error 1 running xcodebuild

You might get an error like this during a Homebrew installation or if you’ve used brew doctor:

1
2
3
4
5
6
7
8
9
10
Warning: Your Xcode is configured with an invalid path.
You should change it to the correct path. Please note that there is no correct
path at this time if you have *only* installed the Command Line Tools for Xcode.
If your Xcode is pre-4.3 or you installed the whole of Xcode 4.3 then one of
these is (probably) what you want:

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

DO NOT SET / OR EVERYTHING BREAKS!

The solution depends on what you’ve got installed.

Firstly, check that you have the latest version of Xcode (or the latest version of the Xcode Command Line Tools).

If you have the Xcode Command Line Tools installed, you can try setting the Xcode path using the xcode-select command:

1
sudo xcode-select -switch /

This points xcode-select to the /usr/bin/xcodebuild location of the Command Line Tools, but can lead to Homebrew hanging (it explicitly warns against this).

A better solution is to install Xcode (which is a bit silly to install a huge application to run some command line tools, but there you go).

If you have the full installation of Xcode installed, you can set the Xcode path using a more complete xcode-select command:

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

If you’re wondering what caused all this kerfuffle, it was the changes in Xcode 4.3 that removed the Command Line tools and the /Developer directory that caused some of these things to go haywire.

Comments