LinuxCommandLibrary

cargo-fetch

Download dependencies without building a project

TLDR

Fetch dependencies specified in Cargo.lock (for all targets)

$ cargo fetch
copy

Fetch dependencies for the specified target
$ cargo fetch --target [target_triple]
copy

SYNOPSIS

cargo fetch [OPTIONS]

PARAMETERS

--manifest-path <PATH>
    Path to Cargo.toml file

--target <TRIPLE>
    Fetch dependencies for specific target triple

--target-dir <DIR>
    Directory for generated artifacts (rarely used)

-p <SPEC>, --package <SPEC>
    Fetch only matching package(s)

--workspace
    Fetch for all workspace members

--locked
    Do not update existing Cargo.lock

--frozen
    Require up-to-date Cargo.lock and cache

--offline
    Operate without network (needs prior fetch)

-v, --verbose ...
    Increase verbosity (repeatable)

-q, --quiet
    Suppress all output

--color <WHEN>
    Color output control (always/never/auto)

-Z <FLAG>...
    Unstable nightly Cargo features

DESCRIPTION

cargo fetch is a Cargo subcommand that downloads all dependencies for a Rust project to the local registry cache (usually $HOME/.cargo/registry) without compiling anything. It resolves dependencies from Cargo.toml and Cargo.lock (generating the lockfile if absent), fetching crates from crates.io or git repositories.

This is ideal for CI/CD pipelines to prefetch deps, speeding up builds, or enabling offline work. After fetching, cargo build --offline or cargo test --offline can run without network. It supports multiple targets, workspaces, and specific packages.

Fetching respects the lockfile for reproducibility; use --locked or --frozen to enforce it. Git dependencies are cloned shallowly. No artifacts are built—only source tarballs or repos are cached. Useful for container images or air-gapped environments.

Requires Rust and Cargo installed. Runs in project root or specified --manifest-path. Verbose output shows download progress.

CAVEATS

cargo fetch downloads source but not binaries; building still requires compiler. Git deps use shallow clones. Fails if network needed without prior cache.

EXAMPLES

cargo fetch
cargo fetch --target aarch64-unknown-linux-gnu
cargo fetch -p tokio --locked
cargo fetch --workspace --offline

CACHE LOCATION

Crates cached in $CARGO_HOME/registry/cache and $CARGO_HOME/registry/src; configurable via CARGO_HOME.

HISTORY

Introduced in Cargo 0.1.0 (July 2014) as part of initial Rust package manager release. Evolved with Cargo workspaces (0.19, 2017) and target support.

SEE ALSO

Copied to clipboard