Skip to content

the BOOK Ch. 1.1 Installation, "Working Offline": cargo add does not download crates, so --offline fails #4817

Description

@slisanz

Section

Introduction "Working Offline with This Book"

Problem

The section states that running

cargo new get-dependencies
cd get-dependencies
cargo add rand@0.8.5 trpl@0.2.0

"will cache the downloads for these packages so you will not need to
download them later."

On current Cargo, cargo add only updates the registry index and writes
Cargo.lock. It does not download the .crate files, so a later
--offline build fails.

Steps to reproduce

# starting from an empty CARGO_HOME
cargo new get-dependencies
cd get-dependencies
cargo add rand@0.8.5 trpl@0.2.0

ls $CARGO_HOME/registry/
# -> only `index`; no `cache/`, no `src/`

cargo build --offline

Expected

The build succeeds using the cached packages.

Actual

error: failed to download `ahash v0.8.12`

Caused by:
  attempting to make an HTTP request, but --offline was specified

Running plain cargo build right after shows the packages had not been
fetched yet:

Downloaded 156 crates (15.0MiB) in 11.55s

Only after that does --offline work.

Suggested fix

Add a fourth step (cargo build or cargo fetch) so the crate sources
are actually downloaded before going offline.

Environment

  • cargo 1.98.0 (797e8a9bc 2026-08-05)
  • rustc 1.98.0 (88d9e12ae 2026-08-18)
  • Windows 11

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions