Skip to content
Latchkey

Cargo "failed to select a version" - Fix Resolution in CI

Cargo could not find a single version of a crate that satisfies every requirement at once. Two of your dependencies demand incompatible version ranges of the same shared crate.

What this error means

cargo build or cargo update aborts with failed to select a version for the requirement (or ...for X (locked to ...)), listing which crates required what. It is deterministic - the same Cargo.toml fails the same way every run.

cargo output
error: failed to select a version for the requirement `rand = "^0.9"`
candidate versions found which didn't match: 0.8.5, 0.8.4, ...
location searched: crates.io index
required by package `mycrate v0.1.0`

Common causes

Two crates pin incompatible ranges

Dependency A requires rand = "0.8" while B requires rand = "0.9". Because the major/minor versions are SemVer-incompatible, no single version satisfies both.

A requirement no version on the index matches

A typo or a too-new requirement (e.g. "^0.9" when only 0.8.x is published) leaves the resolver with no candidate that fits.

How to fix it

Read the conflict and align the requirement

  1. Read which crate and which two requirements conflict in the error.
  2. Relax or bump your own requirement so it overlaps what dependencies need.
  3. If two third-party crates conflict, upgrade the lagging one to a release that accepts the newer shared crate.

Inspect the dependency tree

See every crate that depends on the conflicting package and the version each requires.

Terminal
cargo tree -i rand
cargo tree --duplicates

Update within the allowed range

If a compatible version exists but the lockfile is stale, update just that crate.

Terminal
cargo update -p rand

How to prevent it

  • Use caret requirements rather than exact = pins unless a pin is genuinely required.
  • Upgrade related crates together so shared dependencies stay compatible.
  • Run cargo tree --duplicates to spot diverging versions early.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →