← Writing

Post

Rust Toolchain: A Complete Guide to Managing and Configuring Your Rust Environment

How to manage Rust with rustup: release channels, toolchain overrides, components and build profiles.

15 January 2025 Anatolii Maltsev 2 min read Systems & tooling rust basic

The Rust toolchain is a collection of tools and components that streamline the development, building and maintenance of Rust projects. This guide covers how to use rustup to manage compiler versions and components, what the release channels are, how to configure build profiles, and how to apply overrides for specific projects.

rustup

If you want to start using Rust in your projects, start here. The basic Rust setup is managed by the rustup utility.

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

This will install rustup, rustc, cargo and configure $PATH. By default the host platform targets are installed (e.g. x86_64-pc-windows-msvc).

  • To get a list of installed toolchains and check the active one
>  rustup toolchain list
stable-x86_64-pc-windows-msvc (active, default)
1.74.0-x86_64-pc-windows-msvc
  • Or a command that will display additional information about installed targets.
> rustup show

installed toolchains
--------------------
stable-x86_64-pc-windows-msvc (active, default)
1.74.0-x86_64-pc-windows-msvc

active toolchain
----------------
name: stable-x86_64-pc-windows-msvc
active because: it's the default toolchain
installed targets:
thumbv6m-none-eabi
wasm32-unknown-unknown
x86_64-pc-windows-msvc
  • To find the path to the toolchain
> rustup which rustc
C:\..\stable-x86_64-pc-windows-msvc\bin\rustc.exe

Channels

Rust is developed in three parallel branches, and rustup can also install custom versions of Rust:

  • stable, the most reliable, updated every 6 weeks

  • beta, a “preview” of the next stable, updated every 6 weeks

  • nightly, daily builds, including the latest (but unstable) features

  • custom, custom versions of Rust

  • To install any of the channels

    rustup toolchain install stable
    rustup toolchain install beta
    rustup toolchain install nightly
  • To update the corresponding toolchains
    rustup update stable
    rustup update beta
    rustup update nightly
  • To install the exact version
    rustup install 1.74.0-x86_64-pc-windows-msvc

Overrides and profiles

  • Set the default toolchain for the system
    rustup default nightly
  • To switch the toolchain for a specific project
    cd project-dir
    rustup override set nightly
  • Custom profiles. In ~/.cargo/config.toml you can set profiles:
[profile.dev]
debug = true
incremental = true

[profile.release]
opt-level = 3
debug = false
lto = "fat"
panic = "abort"

Components

  • Each installed toolchain can be upgraded with components
    rustup component add clippy fmt rust-src rust-analyzer
    rustup component add llvm-tools-preview
    rustup component add miri
  • To install a component in another toolchain
    rustup +nightly component add rustfmt
  • Check all installed components on the active toolchain
    rustup component list
  • Remove a component from the active toolchain
   rustup component remove clippy

Best practice

To ensure that the program runs identically on different machines, use the rust-toolchain.toml file.

[toolchain]
channel = "1.70.0"          # 1.70.0 v on stable channel
components = ["rust-src", "clippy", "rustfmt"]
targets = ["thumbv6m-none-eabi"]

[profile.release]
opt-level = "z"             # size optimization
lto = true                  # link-time optimization

The next time cargo build runs it will automatically install the required toolchain, components and targets on your machine.

Neighbors in time

when name
2025-01 Actix-web AI Agent Read →
2024-12 std web_server Read →

Related: the posts that share this one's subject, and where the thread goes next.