Is it safe to delete Swift Package Manager’s caches?
- Yes. The shared cache in
~/Library/Caches/org.swift.swiftpmand each package’s.buildfolder are fetched or built again. Keep~/Library/org.swift.swiftpm, which holds configuration and security records, not cache. - What it costs you: the next resolve fetches packages again, and the next build starts from scratch.
- Does it come back? Yes, at the versions pinned in
Package.resolved. - SiftMac’s verdict: Rebuilds
1. Where SwiftPM keeps things
- **
~/Library/Caches/org.swift.swiftpm** is the shared cache used by every package you build with theswifttools, including copies of package repositories and cached manifests.~/.swiftpm/cacheis a link to it. - **
~/Library/org.swift.swiftpm** holds SwiftPM’s shared configuration and its security folder, linked from~/.swiftpm/configurationand~/.swiftpm/security. The security folder keeps fingerprints of package versions you’ve downloaded, so SwiftPM can warn if a version’s contents change later. - **
.build** in each package holds that package’s dependency checkouts and build products, made byswift build.
Xcode projects that use Swift packages keep their checkouts and build products in the project’s DerivedData folder instead, which clears the way the DerivedData guide describes.
2. Where they are
~/Library/Caches/org.swift.swiftpm
~/Library/org.swift.swiftpm
~/Projects/MyPackage/.build
The --cache-path, --config-path and --scratch-path options point a single command elsewhere; .build is the default scratch path.
3. How big they get
du -sh ~/Library/Caches/org.swift.swiftpm
du -sh ~/Projects/MyPackage/.build
The shared cache keeps repository copies for the packages you’ve resolved, so its size follows how many packages you use and how long their Git histories are. A package’s .build grows with its dependencies and every configuration you’ve built.
4. How to clear them
SwiftPM has one command for each level:
| Command | What it removes |
|---|---|
swift package clean | Build artifacts in .build; dependency checkouts stay |
swift package reset | The package’s complete cache and build directory |
swift package purge-cache | The global repository cache shared by all packages |
cd ~/Projects/MyPackage
swift package purge-cache
swift package reset
In Xcode, the File › Packages menu has Reset Package Caches and Resolve Package Versions for the open project.
Leave ~/Library/org.swift.swiftpm in place. Deleting it frees little and throws away your SwiftPM configuration and the fingerprint records it checks packages against.
5. What happens afterwards
- The next
swift buildorswift package resolvefetches each dependency again at the versions inPackage.resolved, so it needs the network and takes longer on a slow connection. - After
reset, or deleting.build, the next build compiles everything, dependencies included. - Xcode resolves packages again the next time it opens the project.
Package.swift,Package.resolvedand your sources aren’t touched.
Questions
What’s the difference between swift package clean and reset?
clean deletes build artifacts and keeps dependency checkouts, so the next build recompiles without fetching anything. reset empties the package’s whole cache and build directory, so the next build fetches dependencies too.
Is ~/Library/org.swift.swiftpm a cache?
No. It’s SwiftPM’s configuration and security folder. The cache is ~/Library/Caches/org.swift.swiftpm.
Will purge-cache change my package versions?
No. Package.resolved pins them; purging only means they’re fetched again.
Does deleting DerivedData clear Swift packages for Xcode projects?
For that project, yes: Xcode keeps its package checkouts in DerivedData and fetches them again when you next open and build the project.
How SiftMac handles it. Its App caches category lists ~/Library/Caches/org.swift.swiftpm as Swift packages with a Rebuilds verdict and clears what’s inside, keeping the folder. Under Developer files it lists .build folders next to a Package.swift in projects unchanged for 1, 3 or 6 months, and Xcode DerivedData for projects you haven’t opened in that time.
Download SiftMac · scanning is free, and so is your first 2 GB of cleaning · See how it works