Skip to content
Latchkey

cargo fetch: Usage, Options & Common CI Errors

Pre-download every dependency before building.

cargo fetch downloads all dependencies listed in Cargo.lock into the local registry cache without compiling. Pairing it with --offline builds isolates network flakiness from your build step.

What it does

Resolves the lockfile and downloads each dependency crate into $CARGO_HOME. It performs no compilation, so a later cargo build --offline can run with no network.

Common usage

Terminal
cargo fetch --locked                          # fetch exactly the lock
cargo fetch --target x86_64-unknown-linux-musl
cargo build --offline --release               # build with no network

Common CI error: missing crate when offline

cargo build --offline fails with "error: failed to download ... attempting to make an offline request" because a needed crate (often a target-specific dependency) was never fetched. Fix: run cargo fetch with the same --target you build for so all target-gated dependencies are downloaded.

Options

FlagEffect
--lockedFetch exactly what Cargo.lock pins
--target <triple>Fetch target-specific deps

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →