How to clear the Swift Package Manager and CocoaPods cache
Apple platform dependencies live in several caches, and each tool has its own. They are among the easier things to reclaim, because every one of them downloads again when needed.
Swift Package Manager
SwiftPM keeps a global cache of the repositories it downloads, and each package build has its own build folder.
The global cache. Clear it with:
swift package purge-cache
Per its own help text, this purges the global repository cache. The folder it lives in is usually:
~/Library/Caches/org.swift.swiftpm
One package’s build files. In a package folder, delete its build artifacts:
swift package clean
Or remove the whole .build folder, which also removes checked-out dependencies:
rm -rf .build
Packages in an Xcode project. When you add a Swift package inside Xcode, it is checked out into the project’s folder under DerivedData, in a SourcePackages subfolder. Clearing DerivedData removes it too, and Xcode fetches the packages again on the next build.
CocoaPods
CocoaPods caches the pods it downloads. Clear the cache with:
pod cache clean --all
Without --all, you are asked which pod to clear, and pod cache clean NAME clears one. The cache folder is:
~/Library/Caches/CocoaPods
The Pods folder in each project is a separate thing. It is created by pod install. If your repository does not commit it (most do not), you can delete it and run pod install again. If your repository does track the Pods folder, deleting it shows up as a huge change in git. Leave it alone then.
Carthage
Carthage keeps its downloads here:
~/Library/Caches/org.carthage.CarthageKit
Delete that folder to clear them. In a project, the Carthage/Build folder holds the built frameworks, and carthage bootstrap rebuilds or downloads them again.
See the sizes first
du -sh ~/Library/Caches/org.swift.swiftpm ~/Library/Caches/CocoaPods ~/Library/Caches/org.carthage.CarthageKit 2>/dev/null
What it costs
- A slower next build, since dependencies are downloaded again, and a need for the internet.
- Nothing in your own code. The repositories stay on their servers.
The rest of the Xcode clutter
These caches are small next to the Xcode folders. Check DerivedData, iOS DeviceSupport and simulator runtimes next, or use the full checklist.
Quick answers
Is it safe to delete the Swift Package Manager cache?
Yes. swift package purge-cache clears the global cache of repositories. Your packages are downloaded again the next time they are needed.
Should I delete the Pods folder?
It is safe if the Pods folder is not committed to git. pod install recreates it. If your repository tracks Pods, leave it alone.
What is the difference between swift package clean and purge-cache?
swift package clean deletes the build artifacts of the current package. purge-cache clears the global cache of downloaded repositories that is shared between packages.