Reinstalling Xcode

I ran into a problem with my Xcode install. I had actually just dragged it over from another volume, and this seemed to work, but I was having some trouble running Instruments, so I decided I'd just reinstall it. I uninstalled Xcode, went to redownload it, but the Mac App Store still said it was installed.

Hmm. Now what? There is no direct download link for Xcode; the only way to get it is through the store.

When you get Xcode through the Mac App Store, what you actually get is an app called "Install Xcode".

You run this app and it installs Xcode. It leaves itself in your /Applications folder, and it's this app that has the Mac App Store receipt file identifying it as an app that's installed, so normally all you need to do is get rid of this "Install Xcode" application for the store to stop seeing Xcode as installed.

But this didn't work for me. I removed the installer, went back to the store, and it still wouldn't let me download.

To figure out how the App Store was finding Xcode installed, I used the fs_usage tool:

sudo fs_usage >~/out.txt

Run this in Terminal before starting the App Store. This command will log all file system activity to a file named 'out.txt' in your home folder. With it running, launch the App Store. Then, back in the console, hit Ctrl-C to stop fs_usage, and open the out.txt file in an editor. Search for the string "Xcode", and you should see some lines like this:

10:04:36 lstat64 /Volumes/Steve's Laptop Backup/Applications/Install Xcode.app 0.000033 App Store
10:04:36 getattrlist /Volumes/Steve's Laptop Backup/Applications/Install Xcode.app 0.000006 App Store
10:04:36 getattrlist /Volumes/Steve's Laptop Backup/Applications/Install Xcode.app 0.000009 App Store

Aha! I had a drive mounted that had an old Applications folder, where the installer was already downloaded. I have no idea how I would have found this otherwise.

(I had tried searching for the Xcode installer using Spotlight but I had told Spotlight not to index that backup drive, so it didn't find it).