Clear Xcode DerivedData and old simulators safely
If you build iOS or macOS apps, Xcode is probably the biggest reason your Mac keeps running out of space. Most of it is not Xcode itself but what it leaves behind: build data for every project you ever opened, simulator devices full of test installs, and runtimes for iOS versions you stopped testing on years ago.
All of it can be cleared safely if you know which folder is which. This post covers each one, the commands to clear it, and what to keep.
Check what Xcode is using first
Before deleting anything, see where the space actually is. This prints the size of each Xcode folder in your home folder:
du -sh ~/Library/Developer/Xcode/DerivedData \
~/Library/Developer/Xcode/Archives \
~/Library/Developer/Xcode/"iOS DeviceSupport" \
~/Library/Developer/CoreSimulator/Devices 2>/dev/null
Simulator runtimes are not in your home folder. List them, with their size, using xcrun simctl runtime list -v, or open Xcode › Settings › Components.
DerivedData: safe to delete, any time
~/Library/Developer/Xcode/DerivedData holds intermediate build products, indexes and logs, one folder per project. Xcode recreates everything in it on the next build. The only cost is that the next build and the first indexing run take longer.
Quit Xcode first, then:
rm -rf ~/Library/Developer/Xcode/DerivedData/*
To clear just one project, delete its folder inside DerivedData (they are named after the project plus a hash), or use Product › Clean Build Folder in Xcode while that project is open. If you changed the DerivedData location, Xcode › Settings › Locations shows where it is.
Deleting DerivedData is also the classic fix for strange build errors and a stuck indexer, so it is worth knowing even when you have plenty of space.
Simulator devices
Every simulator device you create has its own folder in ~/Library/Developer/CoreSimulator/Devices, with the apps you installed and the data they wrote. Two kinds pile up:
- Unavailable devices: devices whose runtime is no longer installed, or no longer supported by your current Xcode. They can’t even boot.
- Old devices you no longer use: for example an iPhone model you created once to check a layout.
Remove all unavailable devices with one command:
xcrun simctl delete unavailable
To remove a device you no longer need, find its ID and delete it:
xcrun simctl list devices
xcrun simctl delete <device-id>
If you want to keep a device but throw away the apps and data inside it, erase it instead. It must be shut down first:
xcrun simctl erase <device-id>
Avoid xcrun simctl delete all and xcrun simctl erase all unless you really mean it: they remove or reset every device, including the one you test on every day.
Simulator runtimes: the biggest win
Runtimes are the iOS, watchOS, tvOS and visionOS system images that simulators boot from. Each one is several gigabytes, and they stay installed after you stop using them.
List them first:
xcrun simctl runtime list
Then delete what you don’t need. --dry-run shows what would go without deleting anything:
xcrun simctl runtime delete --notUsedSinceDays 90 --dry-run
xcrun simctl runtime delete --notUsedSinceDays 90
You can also delete runtimes that can no longer be used with --unusable, or a single one by its identifier. Xcode › Settings › Components does the same thing with a button.
Keep the runtime for the lowest iOS version your app supports if you still test on it. You can download any runtime again later from the same Components pane, but it is a large download.
Device support files
When you connect an iPhone or iPad and run on it, Xcode copies debug symbols for that exact iOS version into ~/Library/Developer/Xcode/iOS DeviceSupport. A new folder appears for every iOS update, and the old ones are never removed.
Folders for iOS versions none of your devices run anymore can go. Delete them in Finder, or with rm -rf on the specific folder. Quote the path, because the folder names contain spaces: rm -rf ~/Library/Developer/Xcode/"iOS DeviceSupport"/"<version folder>". If you connect a device with that version again, Xcode copies the files again, which takes a few minutes.
Archives: delete with care
~/Library/Developer/Xcode/Archives holds every build you archived for TestFlight or the App Store. They are the one Xcode folder you should not clear blindly: an archive contains the debug symbols (dSYMs) you need to read crash reports from that release.
Open Window › Organizer › Archives in Xcode, and delete archives of versions you no longer support. Keep the ones for releases people still run, unless your dSYMs are stored elsewhere, for example uploaded to your crash reporting service.
Caveats
- Quit Xcode and the Simulator before deleting DerivedData or devices. Deleting files under a running build can leave Xcode confused until you restart it.
rm -rfdoes not use the Trash. Double-check the path before you press Return, and never run it with a variable that might be empty.- The first build after clearing DerivedData is a full build. Plan the cleanup for a moment when that is fine, not five minutes before a demo.
- Runtimes are stored outside your home folder, so the
ducommand above doesn’t count them. Check the free space of the whole disk after deleting one. - macOS Storage settings count simulators under System Data, not Developer, which is why the Developer figure there often looks far too small.
The faster way: CCToolify
Smart Clean in CCToolify finds DerivedData, simulators, simulator caches, SwiftUI Previews, device support files and archives in one read-only scan, together with package manager caches, and shows how much space each one takes.
- Caches such as DerivedData, simulator caches and SwiftUI Previews are pre-selected, and so are unavailable simulators. DerivedData is skipped while Xcode, the Simulator or a build is running.
- Your other simulators open in a review list that shows when you last used each one. Those not opened in 90 days or more are pre-selected, and a simulator that is running is never touched.
- Device support files are listed per version, and the newest one is left unticked.
- Archives are never pre-selected, because they hold the dSYMs you need for crash reports.
- Items move to the Trash, so you can undo. Anything that can’t be undone asks first.
- Everything happens on your Mac. Your files, file names and paths never leave it.
Simulator runtimes are not part of Smart Clean: delete those with xcrun simctl runtime delete or in Xcode › Settings › Components, as shown above.
On our own dev MacBook, one clean freed 193.62 GB. The Disk Scan guide walks through it step by step.