Skip to cookie settings

Where is the Swift Package Manager cache, and can you delete it?

Swift packages are cached in a few places depending on whether you use Xcode or the command line. Here is where, and what is safe to clear.

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 .build folder: if you build from the command line, each package or project gets a .build folder 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 .build folders 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.swiftpm configuration 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

  1. Quit Xcode and any command line builds.
  2. Move ~/Library/Caches/org.swift.swiftpm to the Trash, and empty the Trash. The space comes back only after that. See why the Trash does not free space.
  3. 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.resolved with 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

  1. Run the du command above.
  2. Quit Xcode.
  3. Trash the shared cache folder and empty the Trash.
  4. 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.

Tags:SwiftSwiftPMXcode

See what’s taking up space on your Mac

DiskJoy explains every item and removes nothing until you review it.
Download for Mac

Cookies on diskjoy.com

Your browser sends a Global Privacy Control signal. We honoured it: analytics and marketing cookies are off.

Necessary cookies run this site. Analytics shows us how it is used: if you accept it, Google receives data about your visit. Change this anytime in Cookie Settings. How Google uses data Cookie Policy Privacy policy

Customize

Purpose
Needed for the site to work and to remember your cookie choice.

Cookies

  • sy_consent - Stores your cookie choice (Retention: 12 months)

Other browser storage

  • sy_consent_pending (localStorage) - Queues your choice until it reaches our server (Retention: until deleted)
Purpose
Show us which pages are visited and how the site is used, so we can improve it. Provider: Google Ireland Ltd (Google Analytics 4).

Cookies

  • _ga - Distinguishes visitors to count them (Retention: 400 days)
  • _ga_TP2XMLG27P - Keeps the state of your current visit (Retention: 400 days)

Recipients

Data controller

Sylentis Group sp. z o.o.. Contact: support@diskjoy.com. Privacy policy

Google may process data outside the European Economic Area (EEA). Safeguards: EU-US Data Privacy Framework, standard contractual clauses.

Right to withdraw

You can withdraw consent at any time, as easily as you gave it. Withdrawal does not affect the lawfulness of processing before it.