cargo update --precise: Pin a Dependency Version
cargo update -p <crate> --precise <version> updates only that crate in Cargo.lock to the exact version you name, leaving the rest of the lockfile alone.
Sometimes you need to hold a transitive dependency back (or forward) without bumping everything. --precise edits one line of the lockfile surgically.
What it does
cargo update recomputes Cargo.lock. With -p <crate> --precise <version> it pins exactly that package to the given version (subject to semver constraints in the manifests) without touching unrelated entries. --dry-run shows what would change.
Common usage
cargo update -p time --precise 0.3.36
cargo update --dry-run # preview all updates
cargo update -p tokio # bump tokio within semver
cargo update --workspace # update all members' depsFlags
| Flag | What it does |
|---|---|
| -p <crate> | Limit the update to one package |
| --precise <version> | Set the exact version (requires -p) |
| --dry-run | Show changes without writing Cargo.lock |
| --workspace | Update dependencies of all workspace members |
| --aggressive | Also update transitive dependencies of the named crate |
In CI
Commit the resulting Cargo.lock so --locked builds stay reproducible. A common CI job runs cargo update --dry-run to surface available upgrades without changing anything. Cache ~/.cargo/registry so the index does not have to be re-fetched.
Common errors in CI
"error: failed to select a version for the requirement X = ..." means the --precise version violates a semver constraint in some manifest; loosen the dependency requirement first. "error: package ID specification Y did not match any packages" means the -p name is wrong. "error: --precise can only be used with --package" means you forgot -p.