the BOOK Ch. 1.1 Installation, "Working Offline": `cargo add` does not download crates, so `--offline` fails
Author: slisanzCreated Aug 26, 2026Updated Aug 26, 2026
Section
Introduction "Working Offline with This Book"
Problem
The section states that running
cargo new get-dependencies
cd get-dependencies
cargo add [email protected] [email protected]"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 [email protected] [email protected]
ls $CARGO_HOME/registry/
# -> only `index`; no `cache/`, no `src/`
cargo build --offlineExpected
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 specifiedRunning plain cargo build right after shows the packages had not been
fetched yet:
Downloaded 156 crates (15.0MiB) in 11.55sOnly 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
Source: rust-lang/book