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
Section
Introduction "Working Offline with This Book"
Problem
The section states that running
"will cache the downloads for these packages so you will not need to
download them later."
On current Cargo,
cargo addonly updates the registry index and writesCargo.lock. It does not download the.cratefiles, so a later--offlinebuild fails.Steps to reproduce
Expected
The build succeeds using the cached packages.
Actual
Running plain
cargo buildright after shows the packages had not beenfetched yet:
Only after that does
--offlinework.Suggested fix
Add a fourth step (
cargo buildorcargo fetch) so the crate sourcesare actually downloaded before going offline.
Environment