How to clear the Swift Package Manager and CocoaPods cache on a Mac
Quick answer
In Xcode, File › Packages › Reset Package Caches clears the current project's package caches. For the global caches, run swift package purge-cache (SwiftPM) and pod cache clean --all (CocoaPods). All of it is downloaded again the next time a project resolves its packages.
Where package caches live
| Cache | Where | Clear with |
|---|---|---|
| Swift packages for one project | DerivedData/<Project>/SourcePackages | File › Packages › Reset Package Caches |
| Global SwiftPM cache | ~/Library/Caches/org.swift.swiftpm | swift package purge-cache |
| CocoaPods cache | ~/Library/Caches/CocoaPods | pod cache clean --all |
| Carthage cache | ~/Library/Caches/org.carthage.CarthageKit | Delete the folder |
When to clear them
- Packages won't resolve or Xcode keeps an old version of a package.
- Disk space. On our test Mac the CocoaPods cache alone was 1.4 GB.
Steps
- For one project in Xcode: File › Packages › Reset Package Caches, then File › Packages › Resolve Package Versions.
- For the global SwiftPM cache, in Terminal:
swift package purge-cache - For CocoaPods:
pod cache clean --all
Your Package.resolved and Podfile.lock files aren't touched, so you get the same versions back.
Questions
Is it safe to clear the SwiftPM cache?
Yes. Packages are downloaded again from their repositories the next time a project resolves them. The first build afterwards takes longer.
Will I get different package versions?
No. The versions are pinned in Package.resolved and Podfile.lock, which clearing the cache doesn't change.
Why is my CocoaPods cache so large?
It keeps a copy of every pod version you ever installed, for every project, and never removes old ones by itself.