« Back to Index

Rust: setup toolchain environment

View original Gist on GitHub

Tags: #rust #rustlang #environment #overrides #toolchain

rust environment.md

The default toolchain in rust is “stable”.

A user can execute rustup override set <toolchain> to change the default toolchain (e.g. to “nightly” or a specific toolchain version installed using rustup toolchain install <toolchain>), and this will be reflected when running either rustup show active-toolchain or rustc --version (i.e. either of those latter commands will show the version set to be the same as the specified override). The rustup override set command also takes priority over anything set within a rust-toolchain file:

[toolchain]
channel = "stable" # << this would be overridden by `rustup override set <toolchain>`
targets = [ "wasm32-wasi" ]

NOTE: The behaviour triggered by rustup default <toolchain> is also reflected in the output of rustup show active-toolchain and rustc --version, but (unlike rustup override set) the behaviour concedes to whatever is defined inside the rust-toolchain file.

Additionally the cargo build command can accept a +<toolchain> indicator (e.g. cargo +1.54.0 build) and that can override any of the prior behaviours I’ve covered.

Here are some useful commands for understanding the rust environment:

† Which is different to any specific toolchain that has been manually installed (using rustup toolchain install <toolchain>) and then set to be the default using rustup default <toolchain>.

Refer to https://rust-lang.github.io/rustup/concepts/toolchains.html for more information on the toolchain specification.