how to reinstall xcode command-line tools?

Solution 1:

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

Problem fixed on my side

Solution 2:

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?

  • https://developer.apple.com/downloads/index.action?=command%20line%20tools

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.

Solution 3:

Did you try xcode-select?

man xcode-select

or

xcode-select --switch /Applications/Xcode

Solution 4:

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