/commands/swift/swift-package-update
swift package update: update Swift package dependencies (and Package.resolved)
- tool
- Swift
- versions
- Swift 5.x – 6.x
- os
- macos, linux, windows
swift package update updates the dependencies of a Swift package to the newest versions that the requirements in Package.swift allow, and records the result in Package.resolved. Name a package to update only that one (swift package update swift-argument-parser), or add --dry-run to see what would change without changing anything. swift package resolve does the opposite: it uses the pinned versions.
Update and inspect
# see which dependencies have newer allowed versions
swift package update --dry-run
# update everything, or only one package
swift package update
swift package update swift-argument-parser
# show the resolved dependency graph
swift package show-dependenciesSwiftPM fetches the repositories, picks versions that satisfy every requirement, checks them out in .build/checkouts/ and writes Package.resolved. Review the diff of that file before committing.
Related commands
| Command | What it does |
|---|---|
| swift package update | Move to the newest versions allowed by Package.swift and rewrite Package.resolved |
| swift package update NAME | Update only the named package(s) |
| swift package update --dry-run | List the dependencies that can be updated, change nothing |
| swift package resolve | Fetch the versions pinned in Package.resolved (resolve them if it is missing) |
| swift build --force-resolved-versions | Use only Package.resolved and fail if it is out of date (good for CI) |
| swift package show-dependencies | Print the resolved dependency graph (--format json for tools) |
| swift package reset | Delete the build folder and checkouts, then start fresh |
| swift package add-dependency URL --from 1.0.0 | Add a dependency to Package.swift from the command line |
Version requirements decide what update can do
In Package.swift, .package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.0") allows any 1.x release from 1.3.0, .upToNextMinor(from: "1.3.0") only 1.3.x, and exact: "1.3.0" exactly that version. swift package update never crosses those limits; to adopt a new major version, edit the requirement, then update.
Pitfalls
- Unexpected changes in CI. If CI runs
swift package update, builds can change from one day to the next. In CI, build with--force-resolved-versions(also spelled--only-use-versions-from-resolved-file) so a stalePackage.resolvedfails instead of being rewritten. - Conflicting requirements. When two packages require incompatible versions of the same dependency, resolution fails and SwiftPM explains which requirements conflict; relax one of them.
- Xcode projects. For an Xcode project (not a SwiftPM package), use File > Packages > Update to Latest Package Versions; the command-line tool works on
Package.swift. - Stale checkouts. If resolution keeps failing after you changed a URL,
swift package resetremoves.buildand the checkouts. - Go users. The closest Go command is go mod tidy together with
go get -u.
Confirm it worked
git diff Package.resolved shows the new revisions and versions, and swift package show-dependencies lists the versions now in use. Build and run the tests before committing.
FAQ
Should I commit Package.resolved?
Commit it for applications and command-line tools, so every build uses the same dependency versions. For a library, the file is ignored by packages that depend on yours; many libraries leave it out of version control.
Why does swift package update not install the new major version?
update stays inside the version requirements in Package.swift. A requirement such as from: "1.2.0" allows 1.x only; change it to from: "2.0.0" in the manifest to move to the next major version.
What is the difference between update and resolve?
resolve fetches the versions recorded in Package.resolved (or resolves them if the file is missing) without moving to newer releases. update picks the newest versions allowed by Package.swift and rewrites Package.resolved.