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`

Diagnose it: toolchain, features, or a stale target dir?

Cargo failures that only appear in CI are usually a different toolchain channel, a different feature set resolved by the dependency graph, or a target directory restored from a cache built with different flags.

Terminal
rustc --version --verbose
cargo --version
cat rust-toolchain.toml 2>/dev/null

# which features actually got enabled across the graph?
cargo tree -e features | head -40

# rule out a poisoned cache before anything else
cargo clean && cargo build --locked

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.

Frequently asked questions

What causes Cargo "failed to select a version"?
There are 2 common causes: two crates pin incompatible ranges and a requirement no version on the index matches. Dependency A requires rand = "0.8" while B requires rand = "0.9".
How do I fix Cargo "failed to select a version"?
There are 3 fixes depending on which cause you have: read the conflict and align the requirement, inspect the dependency tree, and update within the allowed range. Work through them in order, since the first is the most common.
What does Cargo "failed to select a version" actually mean?
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.
How do I stop Cargo "failed to select a version" happening again?
Use caret requirements rather than exact = pins unless a pin is genuinely required. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card