Sub topic 11
Updating Rust and Choosing a Release Channel
This chapter assumes you have already installed Rust with rustup and can run rustc --version and cargo --version. You should also be comfortable running shell commands and reading a Cargo.toml file. Here you will learn how rustup keeps your toolchain current, what the three release channels are, and how to pin a project to a specific toolchain.
What a toolchain is
A toolchain is one complete, installed copy of the Rust tools: rustc, cargo, the standard library, and optional components such as Clippy and rustfmt. rustup can keep several toolchains side by side. The rustc and cargo commands on your PATH are small proxies that rustup installs. When you run one, the proxy chooses a toolchain and forwards the call to it.
A toolchain name has up to four parts: a channel or version, an optional date, and a target triple (the platform it builds for). For example, stable-x86_64-unknown-linux-gnu is the stable channel for 64-bit Linux. You can normally leave the platform part off, and rustup fills in your host platform.
The three release channels
Rust ships on a fixed schedule. A new stable release comes out every six weeks. Each release moves through three channels.
| Channel | What it contains | Typical use |
|---|---|---|
| stable | The latest released version. Only bug fixes and finished features. | Applications, libraries, and learning. This is the default. |
| beta | The next stable release, in a six-week testing period. | Checking in CI that your code still compiles with the upcoming release. |
| nightly | A build made every night from the main development branch. | Experimental features that are not yet stable, and some specialized tools. |
Stable is the right choice unless you have a specific reason. Features on nightly can change or disappear without notice, and many require an opt-in attribute such as #![feature(...)] that only nightly accepts.
Updating with rustup
The command rustup update checks every installed toolchain for a newer version and installs it. If you only have stable installed, it updates stable.
rustup updateThe output lists each toolchain and says whether it was updated or was already up to date. The update also refreshes rustup itself.
To see what you have installed and which toolchain is the default, run:
rustup toolchain list
rustup showrustup toolchain list prints one toolchain per line and marks the default with (default). rustup show gives more detail, including the active toolchain for the current directory and why it is active.
To update one toolchain only, name it:
rustup update stableUpdating is safe to do often. A new stable release is meant to be compatible with code that compiled on the previous one, so you rarely need to hold back.
Installing another channel
Install beta or nightly next to stable with rustup toolchain install. Installing a toolchain does not change your default.
rustup toolchain install beta
rustup toolchain install nightlyIf you also want Clippy and rustfmt on that toolchain, add the components while installing:
rustup toolchain install nightly --component clippy rustfmtComponents belong to a single toolchain. Installing Clippy on stable does not give you Clippy on nightly, so run rustup component add for each toolchain that needs it. Use --toolchain to pick which one:
rustup component add clippy rustfmt --toolchain nightlyChoosing which toolchain runs
rustup picks the toolchain for each command using the first rule that applies, in this order.
- A toolchain named with a plus sign on the command line, such as
cargo +nightly build. - The
RUSTUP_TOOLCHAINenvironment variable. - A directory override set with
rustup override. - A
rust-toolchain.tomlfile in the current directory or a parent directory. - The default toolchain.
One-off choice with `+toolchain`
Put the toolchain name right after the command, with a leading plus sign:
cargo +beta test
cargo +nightly build
rustc +stable --versionThis affects only that single command. It is the quickest way to try your project against beta without changing any settings.
Changing the default
The default applies everywhere no other rule matches:
rustup default stableRun rustup default nightly only if you really want nightly everywhere. Most people keep stable as the default and use +nightly when needed.
Pinning a project with `rust-toolchain.toml`
For a project that must build with a specific toolchain, commit a rust-toolchain.toml file at the project root. Anyone who runs cargo inside that directory gets the pinned toolchain, and rustup installs it automatically if it is missing.
[toolchain]
channel = "1.82.0"
components = ["clippy", "rustfmt"]The channel value can be stable, beta, nightly, a dated nightly such as nightly-2025-01-15, or an exact version number. Pinning an exact version makes builds repeatable across machines and CI. The components list makes sure the tools your team needs are installed along with it.
The version number above is only an example. Replace it with a release that exists when you read this, which you can find by running rustc --version on a toolchain you trust.
Directory overrides
rustup override set records a toolchain for one directory in rustup's own settings, outside the project:
rustup override set nightly
rustup override unsetBecause the setting lives on your machine and not in the repository, teammates do not see it. For anything shared, prefer rust-toolchain.toml.
Checking which toolchain is active
When behavior surprises you, ask rustup what it is using:
rustup show active-toolchain
rustc --versionrustup show active-toolchain names the toolchain and tells you where the choice came from, such as a toolchain file or an override. The rustc --version output includes the release number and the commit date, and a nightly version ends with -nightly.
Two toolchains can also be compared directly:
rustc +stable --version
rustc +nightly --versionEditions and toolchains are different things
The edition field in Cargo.toml (for example edition = "2021") selects a set of language rules. The toolchain is the compiler that implements them. A newer compiler understands older editions, so updating the toolchain does not force you to change your edition. An old compiler, however, fails on an edition it does not know. If a Cargo.toml says edition = "2024" and your compiler predates that edition, Cargo reports an error about the unknown edition. The fix is rustup update.
You can also state the oldest compiler your crate supports with the rust-version field:
[package]
name = "hello_cargo"
version = "0.1.0"
edition = "2021"
rust-version = "1.70"
[dependencies]With this set, Cargo refuses to build on an older compiler and tells you which version is required. This is a clearer message than a confusing syntax error.
Common problems
- A command still shows an old version after updating. Another install of Rust, such as one from a system package manager, may appear earlier on your PATH than
~/.cargo/bin. Runwhich rustc(orwhere rustcon Windows) to see which file runs. Remove the duplicate or reorder your PATH. error: toolchain 'nightly' is not installed. The name you gave is not installed. Runrustup toolchain install nightly.- A feature gate error on stable. Messages such as "
#![feature]may not be used on the stable release channel" mean the code needs nightly. Usecargo +nightlyor reconsider the dependency. - Missing component on a new toolchain.
cargo clippyfails with a message that the command is not installed. Add the component to that toolchain. - An update fails partway. Network problems or a proxy can interrupt downloads. Run
rustup updateagain. If a toolchain is damaged, remove it withrustup toolchain uninstall <name>and reinstall.
A worked session
The following sequence shows a typical workflow. It installs beta, tests the project against it, and returns to stable without changing any defaults.
rustup toolchain install beta
cargo +beta test
cargo test
rustup show active-toolchainThe first command downloads beta. The second runs your tests with beta. The third runs them with the default toolchain, which is still stable. The last confirms that stable remains the active toolchain.
Exercise
You run cargo build in a project and the compiler reports that #![feature(let_chains)] is not allowed on the stable channel. You want to build only this project with nightly, and you want your teammates to get the same toolchain when they clone the repository. What do you do, and why not use rustup default nightly or rustup override set nightly?
Show answer
Add a rust-toolchain.toml file at the project root with [toolchain] and channel = "nightly" (or a dated nightly such as nightly-2025-01-15 for repeatable builds). It is committed to the repository, so teammates and CI get the same toolchain and rustup installs it automatically. rustup default nightly changes every project on your machine to nightly. rustup override set nightly affects only your machine and is not shared with the team.
Exercise
After running rustup update, rustc --version still prints an older release than the one rustup reported installing. List two commands you would run to find the cause, and one likely explanation.
Show answer
Run which rustc (or where rustc on Windows) and rustup show active-toolchain. A likely explanation is that a different rustc from a system package manager comes earlier on PATH than ~/.cargo/bin. Another is that a rust-toolchain.toml file or a directory override in the current directory selects an older pinned toolchain.