Rust CLI Troubleshooting: rustup, Toolchains, Components, and Targets

Commands for fixing toolchain mismatches, missing components, and cross-compilation target issues in Rust CLI projects.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Toolchain selection
Show active toolchain details
rustup show

# Display installed toolchains and the active default.

Set the default toolchain
rustup default stable

# Choose the global channel to use by default.

Run Cargo with a specific toolchain
cargo +stable test

# Use a channel explicitly for one command.

Pin a directory to one toolchain
rustup override set stable

# Set a local override for the current project.

See which rustc binary is used
rustup which rustc

# Show the actual executable path selected by rustup.

## Components and targets
List installed and available components
rustup component list

# See whether rustfmt, clippy, or docs are installed.

Install Clippy
rustup component add clippy

# Add the Clippy lint component to the active toolchain.

Install rustfmt
rustup component add rustfmt

# Add the formatter component to the active toolchain.

List installed targets
rustup target list --installed

# Show available target triples already added locally.

Install a target triple
rustup target add x86_64-unknown-linux-musl

# Add support for a cross-compilation target.

Build for a specific target
cargo build --target x86_64-unknown-linux-musl

# Compile using an installed target triple.

Recommended next

No recommendations yet.