Part of: Mac disk cleanup for developers: every cache, what it costs to rebuild (Developers)
Swift Package Manager keeps its shared cache in a folder named org.swift.swiftpm inside ~/Library/Caches. It is safe to delete, because packages download again the next time a project needs them. It is usually small compared with Xcode’s own build folders.
Swift Package Manager, or SwiftPM, is the tool that fetches libraries your Swift project depends on. Xcode uses it too.
Where the files are
You can check for the main locations with du:
du -sh ~/Library/Caches/org.swift.swiftpm ~/Library/org.swift.swiftpm
~/Library/Caches/org.swift.swiftpm: the shared cache of downloaded package repositories. This is the one to clear if you want the cache gone.~/Library/org.swift.swiftpm: configuration and security records. It is small. Leave it.- Inside DerivedData: when you open a project in Xcode, its package checkouts go into the project’s folder in
~/Library/Developer/Xcode/DerivedData. Clearing DerivedData clears those too. See Cleaning up Xcode. - A
.buildfolder: if you build from the command line, each package or project gets a.buildfolder next to its sources. That is build output for that project only.
On the Mac used to check this article, the shared cache was only a few megabytes. The larger sums were in DerivedData. Check yours rather than assuming.
Safe, risky, never
- Safe: the shared cache in
~/Library/Caches/org.swift.swiftpm, and.buildfolders of projects you are not building now. Cost: a download of each package on next resolve, and a rebuild for.build. - Risky: clearing caches while you are offline, or for a package that is hosted on a private server and needs credentials you do not have at hand.
- Never: do not delete the
~/Library/org.swift.swiftpmconfiguration folder as a cache. It holds trust records, not downloads.
What it costs to recreate
SwiftPM downloads each package again from its source, usually a Git host, and checks the version your project asked for. For a handful of packages this takes seconds. For a large dependency tree it can take minutes. Xcode shows “Resolving package graph” while this happens.
If a package’s source has disappeared or the version tag was moved, a re-download can fail or give different code. If your project has a Package.resolved file committed, versions are pinned and you will get the same ones back.
How to clear it
- Quit Xcode and any command line builds.
- Move
~/Library/Caches/org.swift.swiftpmto the Trash, and empty the Trash. The space comes back only after that. See why the Trash does not free space. - Open your project. Xcode resolves its packages again.
SwiftPM also has its own command for purging the cache, listed under swift package --help. It works, but it needs a package folder to run in, so Finder and the Trash are simpler for a one-off.
When Xcode shows a stale package
If a package looks out of date or will not resolve, the problem is often the copy in DerivedData, not the shared cache. Close the project and remove that project’s folder in DerivedData first. It costs a rebuild but nothing else.
The broader picture of Xcode folders is in the Xcode guide and the developer cleanup guide. If you also use CocoaPods, see its cache.
Worked example: what the cache holds
List the shared cache folder:
ls ~/Library/Caches/org.swift.swiftpm
On the Mac used to check this article, it held a manifests folder and a small package-collection.db database with its two companion files. That is a very small cache. The usual large items are not here but in DerivedData, as described above. If the shared cache looks like this on your Mac too, clearing it will not give you much back.
The Swift tool itself is readable too:
swift --version
It prints the Swift version and the target. A new Swift release can change what the cache holds, so look at your own folder and do not rely on this list.
Pin versions so a re-download is safe
A Package.resolved file records the exact version of each package. Commit it for apps. Then a re-download after you clear the cache returns the same code. Library projects often do not commit it, so check your team’s habit before you rely on it.
If something goes wrong
- “Resolving package graph” never finishes. You are offline, or a package host is slow. Wait, or check your network.
- A package fails with an authentication error. It is private. Sign in to the host in Xcode’s account settings and try again.
- A package shows as missing after you clear DerivedData. Xcode fetches it again on the next open. Give it a minute.
- The error mentions a version tag. The tag was moved at the source. Compare
Package.resolvedwith your last working commit.
When not to clean
Do not clear caches when you are about to build offline. If the shared cache is only a few megabytes, leave it.
See sizes in a scan
DiskJoy is our product. Its scan reads your disk and shows how large these folders are, without changing anything. Cleanup is not built yet, so DiskJoy does not delete the package cache today.
Quick checklist
- Run the
ducommand above. - Quit Xcode.
- Trash the shared cache folder and empty the Trash.
- Open the project and let packages resolve.
Frequently asked questions
Where is the Swift Package Manager cache located?
On the Mac used to check this article, the shared cache was a folder named org.swift.swiftpm inside the user Library Caches folder, and configuration lived in a folder of the same name directly in the user Library folder. Xcode also keeps package checkouts inside each project DerivedData folder.
How do I clear the Swift Package Manager cache?
The swift package command has a purge-cache subcommand for the shared cache, and a reset subcommand for a single project build folder. Check swift package --help on your Mac for what your version offers.
Is it safe to delete the Swift package cache?
Yes. Packages are downloaded again from their source the next time a project resolves its dependencies. You need a network connection for that.