rustup — Toolchain Management
rustup is the official toolchain multiplexer and version manager for Rust. It installs, updates, and switches between different compiler release channels (stable, beta, nightly), pinned historical compiler versions, optional developer components (rustfmt, clippy, rust-analyzer), and cross-compilation targets.
How rustup Works: Proxy Shims
When you run rustc or cargo, you do not invoke a compiler binary directly. Instead, every executable in ~/.cargo/bin/ is a lightweight proxy shim managed by rustup.
When invoked, the shim determines which toolchain is active for the current directory and forwards the command to the corresponding toolchain directory inside ~/.rustup/toolchains/:
User runs `cargo build`
|
v
~/.cargo/bin/cargo (rustup proxy shim)
|
| Checks active toolchain priority:
| 1. `+toolchain` command-line argument (`cargo +nightly build`)
| 2. `RUSTUP_TOOLCHAIN` environment variable
| 3. `rustup override` set for the current directory
| 4. `rust-toolchain.toml` file in project or parent directory
| 5. Global default toolchain (`~/.rustup/settings.toml`)
v
~/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo
Essential rustup Commands
| Command | Description |
|---|---|
rustup show |
Displays the active toolchain, installed toolchains, and active targets for the current directory |
rustup update |
Updates all installed toolchains and rustup itself to their latest releases |
rustup default <toolchain> |
Sets the global default toolchain (such as stable, nightly, or 1.85.0) |
rustup toolchain list |
Lists all toolchains installed on the machine |
rustup toolchain install <name> |
Downloads and installs a specific toolchain (beta, nightly, 1.84.0, nightly-2025-02-01) |
rustup toolchain uninstall <name> |
Removes an installed toolchain from disk |
rustup component list --installed |
Lists installed components (rustfmt, clippy, rust-src, llvm-tools) for the active toolchain |
rustup component add <name> |
Installs an optional component for the active toolchain |
rustup target list --installed |
Lists installed compilation target architectures |
rustup target add <triple> |
Installs the precompiled standard library (rust-std) for a cross-compilation target |
rustup doc |
Opens the offline local copy of the Rust documentation and standard library reference in a browser |
rustup which rustc |
Prints the exact filesystem path to the active rustc binary inside ~/.rustup/toolchains/ |
rustup self update |
Updates rustup itself without updating toolchains |
rustup self uninstall |
Completely uninstalls rustup, ~/.cargo, and ~/.rustup |
Inspect your current environment with rustup show:
rustup show
Default host: aarch64-apple-darwin
rustup home: /Users/username/.rustup
installed toolchains
--------------------
stable-aarch64-apple-darwin (active, default)
nightly-aarch64-apple-darwin
active toolchain
----------------
name: stable-aarch64-apple-darwin
active because: it's the default toolchain
installed targets:
aarch64-apple-darwin
wasm32-unknown-unknown
Installing and Switching Toolchains
You can keep multiple toolchains installed side by side without conflict:
# Install the nightly channel and a pinned historical release
rustup toolchain install nightly
rustup toolchain install 1.84.0
One-Off Invocation with +<toolchain>
To run a single cargo or rustc command using a specific toolchain without changing your global default, pass +<toolchain> as the very first argument:
rustc +nightly --version
cargo +1.84.0 check
rustc 1.87.0-nightly (f4a216d28 2025-03-02)
Pinning a Project Toolchain (rust-toolchain.toml)
Teams and open-source repositories often pin the exact toolchain, components, and targets required to build a project by placing a rust-toolchain.toml file in the project root:
[toolchain]
channel = "1.85.0"
components = ["rustfmt", "clippy", "rust-src"]
targets = ["wasm32-unknown-unknown"]
profile = "default"
When any developer runs cargo build or cargo test inside a directory containing rust-toolchain.toml, rustup automatically reads the file, downloads the specified toolchain and components if they are missing, and executes the command using that exact version.
Managing Components (rustup component)
Each toolchain bundles optional tools and library source files called components:
| Component Name | Purpose |
|---|---|
rustc |
The Rust compiler (installed by default) |
cargo |
The package manager and build tool (installed by default) |
rust-std |
Precompiled standard library for the target platform (installed by default) |
rustfmt |
Automatic code formatter (cargo fmt, included in default profile) |
clippy |
Static analysis linter (cargo clippy, included in default profile) |
rust-docs |
Offline HTML documentation (rustup doc, included in default profile) |
rust-src |
Source code of the Rust standard library (used by rust-analyzer for jump-to-definition and by cargo -Z build-std) |
rust-analyzer |
Official Language Server Protocol (LSP) binary for code editors |
llvm-tools |
Bundled LLVM utilities (llvm-objdump, llvm-nm, llvm-size, llvm-profdata for coverage) |
miri |
Interpreter for detecting undefined behavior in unsafe code (nightly only) |
Add a component to your active toolchain with rustup component add:
rustup component add rust-src rust-analyzer
Managing Cross-Compilation Targets (rustup target)
Because rustc uses LLVM as its backend, every installed rustc binary is already a cross-compiler capable of emitting machine code for dozens of CPU architectures. To cross-compile for another platform, you only need to install that target's precompiled standard library (rust-std) via rustup target add:
# Install the WebAssembly and Linux x86_64 standard libraries
rustup target add wasm32-unknown-unknown
rustup target add x86_64-unknown-linux-gnu
# Compile a library crate to WebAssembly
cargo build --target wasm32-unknown-unknown --release
Reading Offline Documentation (rustup doc)
rustup installs a complete offline copy of the Rust documentation, which works without an internet connection:
| Command | Opens |
|---|---|
rustup doc |
Main Rust documentation portal |
rustup doc --std |
Standard library API reference (std) |
rustup doc --book |
The Rust Programming Language book |
rustup doc --reference |
The Rust Reference language specification |
rustup doc --nomicon |
The Rustonomicon (guide to unsafe Rust) |
rustup doc std::vec::Vec |
Directly opens the API page for Vec<T> |