macOSLinux

Where Does Swift Package Manager Store Builds and Caches?

SwiftPM builds into .build beside your package, with shared caches elsewhere. Scratch paths, reset commands and Xcode differences.

Last updated

Swift Package Manager centers on a .build folder at the package root holding checkouts, compiled artifacts and the package database. Delete it any time: swift build recreates everything from Package.swift and Package.resolved. That makes .build the first suspect for haunted incremental builds.

Shared caches (manifests, dependency mirrors) live outside the project and move with --cache-path. Override the scratch dir per invocation with --scratch-path instead of fighting defaults. Reset surgically: swift package clean drops build artifacts, swift package reset wipes the whole tree, purge-cache targets just the shared caches.

Where SPM stores this, by platform

macOS
<package root>/.build

Checkouts, artifacts and package DB here for swift build. Xcode builds ignore it entirely and use ~/Library/Developer/Xcode/DerivedData instead, so cache the right one in CI.

Linux
<package root>/.build

Same root-relative role as macOS. Shared manifest caches move with --cache-path. swift package purge-cache clears shared state without touching this folder.

Frequently asked questions

How do I fully clean a SwiftPM build?

Run swift package reset in the package root to wipe .build completely, or swift package clean for artifacts only. Re-resolve with swift package resolve afterwards. Xcode users must clean DerivedData separately since it never reads .build.

Where does SwiftPM keep shared caches?

Outside the project in the shared cache directory, movable with --cache-path. It holds manifests and fetched dependencies shared across packages. Purge it with swift package purge-cache when cross-project weirdness appears.

Notice an outdated path? Let us know.