How to delete Xcode DerivedData
DerivedData is usually the single biggest folder Xcode leaves on your Mac. Here's what it is, whether it's safe to delete, and how to do it.
What is DerivedData?
Every time you build a project, Xcode writes the compiled code, the search index, build logs and SwiftUI preview data to a folder named after the project inside:
~/Library/Developer/Xcode/DerivedData
Xcode never cleans it up on its own. Projects you deleted, renamed or cloned twice all keep their own folder, so after a year of work it's common to find 20 to 50 GB there.
Is it safe to delete?
Yes. DerivedData is a cache. Nothing in it is source code or settings you wrote. If you delete it:
- The next build of each project takes longer, because Xcode compiles everything again.
- Xcode indexes the project again, so code completion is slow for a few minutes.
- SwiftUI previews rebuild the first time you open them.
Close Xcode first. Deleting the folder of a project that is building at that moment can make the build fail; just build again.
How big is yours?
Open Terminal and run:
du -sh ~/Library/Developer/Xcode/DerivedData
To see which projects take the most space:
du -sh ~/Library/Developer/Xcode/DerivedData/* | sort -h
Option 1: from Xcode
- Open Xcode › Settings › Locations.
- Click the small arrow next to the DerivedData path. Finder opens the folder.
- Quit Xcode, then move the project folders you don't need (or all of them) to the Trash.
Product › Clean Build Folder (⇧⌘K) is not the same thing: it only removes the build products of the project that is open, not the index, and not the folders of other projects.
Option 2: from Terminal
To delete everything at once:
rm -rf ~/Library/Developer/Xcode/DerivedData
Xcode creates the folder again the next time you build. To delete a single project, use its folder name, for example rm -rf ~/Library/Developer/Xcode/DerivedData/MyApp-abcdefgh….
Option 3: only what's stale
Deleting everything means rebuilding the project you're working on today, too. A better approach is to delete only:
- folders of projects that no longer exist on your Mac;
- folders you haven't built in a month or more.
Each project folder has an info.plist with the path of the project it belongs to (WorkspacePath), so you can check whether the project is still there. That's exactly what Roomy does for you: it lists every DerivedData folder with its project name and last build, flags the ones whose project was deleted, and pre-selects only the stale ones.
Other Xcode folders worth checking
- Simulator runtimes take 5 to 8 GB each. See how to delete old simulators and runtimes.
- iOS DeviceSupport (
~/Library/Developer/Xcode/iOS DeviceSupport) keeps debug symbols for every iOS version of every device you plugged in. Xcode copies them again when needed. - Archives (
~/Library/Developer/Xcode/Archives) hold your App Store builds and their dSYMs. Keep the ones you still need to symbolicate crashes. - SwiftUI previews (
~/Library/Developer/Xcode/UserData/Previews) can grow to several GB.
Do it in one click with Roomy
Roomy finds everything in this guide, shows what's safe to remove and cleans it for you. Scanning is free.
More guides
How to delete old iOS simulators and runtimes
Simulator runtimes take 5 to 8 GB each. How to list them, delete unavailable simulators and remove old iOS runtimes with Xcode or simctl.
How to free up space on a Mac
Mac storage full? Check these 10 places first: caches, Downloads, iPhone backups, app leftovers, Xcode, node_modules and more, with safe steps for each.