How to Clear Xcode Cache and Derived Data (Full Guide)
In this article
Clearing Xcode cache and derived data forces the IDE to rebuild all project files from scratch, which often resolves stubborn build failures, mysterious linker errors, and performance slowdowns that accumulate over time. When Xcode stores cached build outputs, intermediate object files, and compiled modules, those files can become corrupted, reference outdated code, or simply grow to consume many gigabytes of disk space. Removing these cached artifacts tells Xcode to start fresh, which frequently fixes issues that seem to have no apparent cause. Before proceeding, make sure Xcode is completely closed; leaving it running can lock files and prevent complete deletion.
What You'll Need
- Mac computer with Xcode installed
- Administrator access to your user account
- Finder or Terminal application
Step-by-Step
- Quit Xcode completely. Do not just close the active window; ensure Xcode is not running in the background. You can verify this by checking the Dock for the Xcode icon or using Command+Option+Escape to open the Force Quit Applications window and confirming Xcode is not listed as running.
- Open Finder and navigate to the DerivedData folder. Press Command+Shift+G to open the Go to Folder dialog, then paste the following path: ~/Library/Developer/Xcode/DerivedData/ and press Enter. This folder contains all build outputs, compiled binaries, and index data for every project you have opened in Xcode.
- Select and delete all contents of the DerivedData folder. You can press Command+A to select everything, then move to Trash with Command+Delete, or simply drag the entire folder to Trash and create a fresh one later. Deleting these files is safe because Xcode rebuilds them automatically on your next build.
- Clear the Xcode module cache. Open the Go to Folder dialog again and navigate to ~/Library/Caches/com.apple.dt.Xcode/. This folder stores precompiled module headers and other cached data that speeds up subsequent builds. Delete all contents inside this folder as well.
- Remove old Xcode archives if desired. If you want to free additional space, navigate to ~/Library/Developer/Xcode/Archives/ and delete any old project archives you no longer need. These archives are used for distributing builds but are not required for day-to-day development.
- Empty the Trash. Right-click the Trash icon in your Dock and choose Empty Trash, or press Command+Shift+Delete and confirm. This permanently removes the cached files and frees up disk space.
- Reopen Xcode and rebuild your project. Launch Xcode, open your project, and perform a clean build by pressing Command+Shift+K followed by Command+B. The rebuild process will take longer than usual because Xcode must regenerate all cached data, but subsequent builds will be faster as the cache rebuilds.
Common Mistakes
One frequent error is trying to delete DerivedData while Xcode remains open. When Xcode is running, it locks many of these files to prevent data corruption, and the deletion will be incomplete or will cause errors. Always fully quit the application first, and consider restarting your Mac if you are unsure whether background processes are holding files. Another mistake is confusing the user library folder with the system library folder. The path ~/Library/ points to your personal user library, not the system-level library at /Library/. Using the wrong path means you will not actually clear the Xcode cache. Some users also forget to clear the module cache at ~/Library/Caches/com.apple.dt.Xcode/, which can leave behind corrupted precompiled headers that continue causing build failures even after deleting DerivedData.
Tips
Consider creating a simple shell script or Automator workflow to automate this cleanup process, especially if you find yourself clearing cache frequently. You can also set Xcode to automatically clean DerivedData after each build session by going to Xcode preferences, selecting the Locations tab, and changing the Derived Data location to a custom path that you can easily wipe. For teams using continuous integration, ensure that your CI server also clears cache between builds to prevent cross-contamination of build artifacts. If you work on multiple large projects, you might want to keep DerivedData on a separate drive or partition to avoid filling up your system drive, which you can configure in Xcode preferences under the Locations tab.
Troubleshooting
If you delete DerivedData but build errors persist, the issue likely lies elsewhere. Try also clearing the module cache at ~/Library/Caches/com.apple.dt.Xcode/ as mentioned in the steps above, since corrupted module files can survive a DerivedData deletion. If Xcode crashes during the rebuild process, try deleting the .xcodeproj file's scheme by opening the Xcode project navigator, right-clicking the .xcodeproj file, and choosing Delete the scheme, then recreating it from the Manage Schemes dialog. Persistent indexing problems can sometimes be resolved by deleting the .xcodeproj.xcworkspace directory within your project folder if you are using CocoaPods or Swift Package Manager. When all else fails, a full restart of both your Mac and Xcode often clears hidden system-level locks that prevent clean builds.
Frequently Asked Questions
Will deleting DerivedData delete my source code?
No, DerivedData only contains build outputs, compiled binaries, and indexing data. Your actual source code files remain untouched in your project folder.
How often should I clear Xcode cache?
There is no fixed schedule; most developers clear cache only when encountering build issues or when disk space runs low. Some teams clear it as part of their CI pipeline for every build to ensure consistent results.
Does clearing cache affect my CocoaPods or Swift Package Manager dependencies?
No, your dependencies are stored in the Pods folder or the SPM cache separately. Clearing DerivedData does not remove third-party libraries you have integrated into your project.
Can I use Terminal instead of Finder to delete these folders?
Yes, you can run rm -rf ~/Library/Developer/Xcode/DerivedData/* and rm -rf ~/Library/Caches/com.apple.dt.Xcode/* from the command line for a quicker deletion.