How can I work offline?

I'm at the mercy of an unreliable internet connection.

As well as a delay every time I execute cargo (since internet is slow), I also sometimes get this:

$ cargo --help --offline
info: syncing channel updates for 'nightly-2025-12-30-x86_64-unknown-linux-gnu'
error: failed to download file error=Reqwest(reqwest::Error { kind: Request, url
: "https://static.rust-lang.org/dist/2025-12-30/channel-rust-nightly.toml.sha256
", source: hyper_util::client::legacy::Error(Connect, ConnectError("dns error",
Custom { kind: Uncategorized, error: "failed to lookup address information: Name
or service not known" })) })
error: could not download file from 'https://static.rust-lang.org/dist/2025-12-3
0/channel-rust-nightly.toml.sha256' to '/home/alex/.rustup/tmp/8yekkyrk8frsedtd_
file': error downloading file: error sending request for url (https://static.rus
t-lang.org/dist/2025-12-30/channel-rust-nightly.toml.sha256): client error (Conn
ect): dns error: failed to lookup address information: Name or service not known
: failed to lookup address information: Name or service not known

I would prefer that running cargo with --offline mode would not access the net.

I would prefer to get cargo help without accessing the net.

I would prefer to use stable, but there are several features I'm using that are nightly only.

I have set up a rust-toolchain.toml pointing to a specific nightly, in the hope that using nightly wouldn't trigger internet access each time I use it.

I would prefer to be able to use a specific toolchain without it accessing the net every time.

I understand that if I want a new crate in my project, I'd need internet access to download that. But once it's downloaded, why can't I work offline until I need the next crate? If my internet is down, it can sometimes be troublesome to fix it, and being able to operate offline for an hour or two would be a huge usability improvement for me.

$ cat .cargo/config.toml 
[target.x86-unknown-none]
rustflags = ["-C", "link-arg=-Tlink.x"]

[unstable]
build-std = ["core", "compiler_builtins", "alloc"]

[build]
target = "x86-unknown-none.json"
$ cat rust-toolchain.toml 
[toolchain]
channel = "nightly-2025-12-30"
components = ["rustfmt", "clippy", "rust-src"]
targets = ["x86-unknown-none.json"]

For reference, with the internet working:

$ cargo -vv --help --locked --offline 
info: syncing channel updates for 'nightly-2025-12-30-x86_64-unknown-linux-gnu'
info: latest update on 2025-12-30, rust version 1.94.0-nightly (56f24e00c 2025-1
2-29)                                   
info: component 'clippy' for target 'x86_64-unknown-linux-gnu' is up to date
info: component 'rust-src' is up to date 
info: component 'rustfmt' for target 'x86_64-unknown-linux-gnu' is up to date
warn: Force-skipping unavailable component 'rust-std-x86-unknown-none.json'
Rust's package manager
                    
Usage: cargo [+toolchain] [OPTIONS] [COMMAND]
       cargo [+toolchain] [OPTIONS] -Zscript <MANIFEST_RS> [ARGS]...
...

Any suggestions on how to configure things to work better would be appreciated.

I like cargo and it does make package management easy if you have reliable internet. But because of this and other problems (I'm having to use an external linker anyway because reasons,) perhaps the best thing is to ditch cargo and use some other build system.

1 Like

This should only happen when the rustc toolchain that is configured is not yet downloaded. Rustup doesn't have an offline mode. It will download the toolchain if it isn't available yet, but otherwise will never touch the internet. --offline only applies to cargo, making it try to downgrade/upgrade packages if the requested version is not available locally, but another compatible version is.

I think this is the reason why rustup is trying to use the internet. x86-unknown-none.json is not a target for which a precompiled standard library is available (rustc doesn't have any builtin knowledge of it in the first place), so targets = ["x86-unknown-none.json"] in rust-toolchain.toml is invalid. Try removing it from rust-toolchain.toml, while keeping .cargo/config.toml unchanged.

2 Likes

Nice, thanks that solved the problem.

Note that while this is enabled by default, it is optional. rustup set auto-install disable will disable it. And rustup set auto-self-update disable will stop rustup from updating itself.

Panamax might be useful too: GitHub - panamax-rs/panamax: Mirror rustup and crates.io repositories, for offline Rust and cargo usage.

1 Like