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

> Fix cargo "error: failed to select a version for the requirement" in CI - incompatible version requirements between crates that share a dependency.

Source: https://latchkey.dev/learn/rust/cargo-failed-to-select-a-version  
Updated: 2026-06-25

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.

## 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
```

> Always build with `--locked` in CI. Without it Cargo may update `Cargo.lock` silently, so CI tests a dependency set that is not the one you committed.

## FAQ

### 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.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
