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

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

Problem fixed on my side

  • 18
    This is the way to do it in 2020.
    – shad
    Jan 20, 2020 at 23:39
  • 1
    simple and effective - worked perfectly, thanks!
    – GarethD
    Jan 21, 2020 at 12:32
  • 7
    May go with sudo rm -rf `xcode-select -p` && xcode-select --install just to be safe.
    – AlexV
    Apr 11, 2020 at 3:29
  • 1
    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
    So, for those who face issues with Homebrew CLI suddenly calling Bundler and failing to find the gem after a Mac OS X major upgrade (Big Sur), this is what repaired my problems. It allowed brew doctor to apply its medicine properly. :D Cheers, and thanks @damien-c ! Feb 24, 2021 at 18:19

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.

  • Forgot to mention that I tried that; xcodebuild still unavailable in standard executible dirs. There is one in Xcode.app/Contents/Developer/usr/bin/xcodebuild.
    – sierra
    Jun 10, 2013 at 17:05
  • xcrun will tweak your path if you have multiple toolsets installed. You could just mv those binaries into /usr/bin if you wanted a quick fix. Again with WWDC running as I type this, a new version of Xcode should drop within a day or two...
    – bmike
    Jun 10, 2013 at 17:10
  • Thanks. Are you suggesting copying all the files from that dir?
    – sierra
    Jun 10, 2013 at 17:25
  • Here's a paste of /usr/bin from a clean Mac with the latest command line tools. You can diff it with your listing (ls -la /usr/bin) cl.ly/PYyh to see what needs to be copied and what Apple left in the Xcode.app /Developer folder.
    – bmike
    Jun 10, 2013 at 17:51
  • No dice: $ xcodebuild dyld: Library not loaded: @rpath/DVTFoundation.framework/Versions/A/DVTFoundation Referenced from: /usr/bin/xcodebuild Reason: image not found Trace/BPT trap: 5
    – sierra
    Jun 11, 2013 at 13:46

Did you try xcode-select?

man xcode-select


xcode-select --switch /Applications/Xcode
  • Not available. I mistakenly removed it, and I didn't get it back when reinstalling command line tools.
    – sierra
    Jun 11, 2013 at 13:40

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


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).

  -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 .