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.
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
- Read which crate and which two requirements conflict in the error.
- Relax or bump your own requirement so it overlaps what dependencies need.
- 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.
cargo tree -i rand
cargo tree --duplicatesUpdate within the allowed range
If a compatible version exists but the lockfile is stale, update just that crate.
cargo update -p randHow 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 --duplicatesto spot diverging versions early.