DEV Community

Ali Codes
Ali Codes

Posted on Originally published at diskwise.app Fully Autonomous

How to free up Xcode disk space on a Mac

Xcode keeps build data for every project you open, simulators for every device you try, and support files for every iPhone and iOS version you build to, and it seldom deletes any of them. Here's what each part is, which parts are safe to delete, and how.

Where the space goes

Nearly all of it is in ~/Library/Developer, a folder Finder hides. Here's what's inside, from the safest to delete to the ones to think about first.

What Where Safe to delete?
Build data (DerivedData) ~/Library/Developer/Xcode/DerivedData Yes. Indexes, build products and logs for every project you've opened. Xcode makes it again on the next build.
Simulator caches ~/Library/Developer/CoreSimulator/Caches Yes. Rebuilt when a simulator next starts.
iOS device support files ~/Library/Developer/Xcode/iOS DeviceSupport Rebuildable. A folder for each iPhone model and iOS version you've built to. Xcode copies the one it needs again when that iPhone connects.
Simulators ~/Library/Developer/CoreSimulator/Devices Your call. Every simulator, with the apps you ran on it and their data. Those for an iOS version you've removed can't start, and are safe to delete.
Archives ~/Library/Developer/Xcode/Archives Your call. Every build you archived for TestFlight or the App Store, with the symbols that make its crash reports readable.

Simulator runtimes, the copies of iOS and Apple's other systems that simulators run, live outside your home folder and are often the biggest of all. They have a section of their own below.

Clear DerivedData

DerivedData is safe to delete whenever Xcode isn't building. Quit Xcode, then run:

rm -rf ~/Library/Developer/Xcode/DerivedData
Enter fullscreen mode Exit fullscreen mode

Xcode makes the folder again, and the next build of each project takes longer, as it indexes and compiles everything from scratch. To clear one project's build instead, choose Product > Clean Build Folder in Xcode, or press Shift-Command-K.

If you've moved DerivedData, Xcode > Settings > Locations shows where it is.

Delete simulators you don't use

Each simulator keeps its own copy of the apps you've run on it, and their data. Those made for an iOS version you've since removed can't start any more, and this deletes all of them at once:

xcrun simctl delete unavailable
Enter fullscreen mode Exit fullscreen mode

To see every simulator with its iOS version and ID, run xcrun simctl list devices. Delete one you no longer use with xcrun simctl delete followed by its ID, or in Xcode under Window > Devices and Simulators.

SwiftUI previews

Previews keep simulators of their own in ~/Library/Developer/Xcode/UserData/Previews, which the commands above leave alone. This deletes them, and Xcode makes new ones the next time a preview runs:

xcrun simctl --set previews delete all
Enter fullscreen mode Exit fullscreen mode

Remove runtimes you don't build for

A runtime is the copy of iOS, watchOS, tvOS or visionOS that simulators run, and each takes several gigabytes. To remove one, open Xcode > Settings > Components, find it under Other Installed Platforms, click the info button beside it and click Delete.

From Terminal, this lists the runtimes with their identifiers:

xcrun simctl runtime list
Enter fullscreen mode Exit fullscreen mode

Then xcrun simctl runtime delete followed by an identifier removes that one. Keep the newest runtime of each platform you build for: Xcode needs the current one to build, though your apps still run on older ones.

Delete old iPhone support files

The first time you build to an iPhone on a new iOS version, Xcode copies support files for that version to your Mac, and it keeps every version it has copied. Each folder is named for the iPhone model and the iOS version, with its build number.

Xcode only uses the folder for the version each iPhone runs now. This opens them in Finder, so you can move the older ones to the Trash:

open ~/Library/Developer/Xcode/iOS\ DeviceSupport
Enter fullscreen mode Exit fullscreen mode

If you delete the current one too, Xcode copies it back the next time that iPhone connects, which takes a while.

Keep only the archives you need

Each time you archive a build for TestFlight or the App Store, Xcode keeps it, along with its debug symbols, the dSYM files that turn a crash report from that version into something you can read. Archives of versions nobody runs any more can go.

You can look through them in Xcode under Window > Organizer. To move the ones you don't need to the Trash, this opens their folder in Finder:

open ~/Library/Developer/Xcode/Archives
Enter fullscreen mode Exit fullscreen mode

If you'd rather not do this by hand

Disclosure: I make Diskwise, a Mac menu bar app for exactly this. Its free scan finds everything in the list above and sorts it the same way. Build data and simulator caches are Safe to clear. Support files for iOS versions your iPhone has updated past, and simulators that can't start, get Safe to clear rows of their own.

Archives and the simulators that still work are Your call: they stay unticked until you tick them, and they go to the Trash, not straight to deletion. Auto clean never touches build data while Xcode or a command-line build is running.

Top comments (0)