82

I had serious problems from two versions of Xcode on the same machine. I removed all Xcode app instances & many other non-System 'xcode'-related files, then reinstalled the app (4.6.2), fixing my original problem. But xcodebuild and xcode-select are still not available, which I need to run PhoneGap for iOS. Within Xcode, the Preferences => Downloads => Command-line Tools item is marked "Installed", with no option to delete or re-install. I tried removing xcrun, but that didn't work. How do I fix this?

5 Answers 5

139
  1. I run sudo rm -rf /Library/Developer/CommandLineTools
  2. and then xcode-select --install

Problem fixed on my side

2
  • 2
    You might also need to reset xcode-select's path afterwards (at least I had to), by using sudo xcode-select -r Apr 28, 2020 at 9:57
  • 1
    Homebrew installed a newer version of the dev tools than my OS version allowed Xcode version, so I had to use this to remove it and re-install the tools via XCode instead of homebrew. Aug 16, 2022 at 17:37
10

The command line tools are installed like other OS X packages, so you may need to delete the receipt file from the receipts database (which used to be trivial since you could delete the file from /Library/Receipts but now is more complicated and needs a short article on the receipts database).

Rather than mess with that, why not just download the stand alone installer and wait for a new version of Xcode to clean up your receipts database for you?

This URL is fairly open (even the search engines can index it) but you might need to make a free Safari or free Mac developer account to log in and get this package.

If this happened to me, I'd simply change my Time Machine to exclude system files and then install a new OS onto a spare volume. I'd make a junk admin user that I'll delete and use that user to install Xcode and the command line tools and then finally restore from Time Machine. As long as everything worked, I'd clone that to my main drive or repeat the wipe/reinstall process - whichever is easier for you to perform.

0
6

Did you try xcode-select?

man xcode-select

or

xcode-select --switch /Applications/Xcode
0
1

This seems to work for XCode 5, remove --dry-run to actually perform copy.

sudo rsync -ai --exclude subversion\* --exclude SVN\* /Applications/Xcode.app/Contents/Developer/usr /
sudo ln -sf /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild /usr/bin/

Or go to https://developer.apple.com/downloads/ and search for "xcode" - there are downloadable packages for 10.5 through to 10.10

1

Referring to the help text, running xcode-select -r will reset xcode, which may help with install-time issues.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .