rustup: Set the Default Toolchain in CI
rustup default <toolchain> sets the toolchain cargo uses everywhere; a rust-toolchain.toml or rustup override pins it per directory instead.
Fresh CI installs of rustup may have no default toolchain, so cargo fails immediately. Setting a default, or letting rust-toolchain.toml pin one, is the fix.
What it does
rustup resolves which toolchain to use in priority order: an explicit +toolchain argument, a rust-toolchain.toml/rust-toolchain file, a directory override set with rustup override set, then the global default from rustup default. With none set, cargo cannot pick a toolchain.
Common usage
rustup default stable
# or pin per-directory
rustup override set 1.78.0
# or commit rust-toolchain.toml:
# [toolchain]
# channel = "1.78.0"
# components = ["clippy", "rustfmt"]
cargo buildOptions
| Command / flag | What it does |
|---|---|
| rustup default <ch> | Set the global default toolchain |
| rustup override set <ch> | Pin a toolchain for the current directory |
| rustup override list | Show directory overrides |
| rust-toolchain.toml | Repo-committed pin (channel/components/targets) |
| rustup show | Show the active toolchain and how it was chosen |
| RUSTUP_TOOLCHAIN | Env var that forces a toolchain |
In CI
Prefer committing rust-toolchain.toml so the toolchain is pinned in version control and auto-installed on first cargo invocation; you then need no rustup commands at all. If you install rustup manually with --default-toolchain none, remember to set a default before calling cargo.
Common errors in CI
"error: no default toolchain configured" means rustup is installed but nothing is selected; run rustup default stable or add rust-toolchain.toml. "error: override toolchain 'X' is not installed" means an override file pins a version absent on the runner; install it. "info: syncing channel updates" hanging usually points at a slow/blocked static.rust-lang.org.