TL;DR

  • Installing via rustup keeps toolchains current and easier to manage.
  • Use rustup update periodically to update rustc and Cargo.
  • Prefer cargo check during development for faster feedback than full builds.
  • Run cargo test and cargo clippy -- -D warnings before publishing.
  • cargo-binstall only works for crates that publish compatible prebuilt binaries.
  • Use directory overrides (rustup override set ...) when a project requires a specific toolchain.

Installation

# Linux/macOS (recommended: rustup)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# load Cargo environment for current shell
# sh/bash/zsh/ash/dash/pdksh
. "$HOME/.cargo/env"

# verify
cargo --version
rustc --version

If your shell is fish or nushell, source the matching env file that rustup prints after install.

Overview

rustup manages Rust toolchains, components, and targets. cargo is Rust’s package manager and build tool for dependencies, builds, tests, and publishing.

Rustup Toolchain Workflow

# update stable toolchain and bundled Cargo/rustc
rustup update

# optional: check active toolchains
rustup show

With a working toolchain in place, the next step is the day-to-day Cargo workflow.

Useful rustup operations

# install additional toolchains
rustup toolchain install stable
rustup toolchain install nightly

# set default toolchain globally
rustup default stable

# pin toolchain for current project directory
rustup override set nightly

# add common components
rustup component add rustfmt clippy

# add compilation target (example: musl static Linux)
rustup target add x86_64-unknown-linux-musl

Fast Binary Installs with cargo-binstall

cargo-binstall installs prebuilt binaries for many crates (when available), which is usually faster than compiling from source.

# install cargo-binstall itself
cargo install cargo-binstall

# install a crate via prebuilt binaries when available
cargo binstall ripgrep

Keep Installed Cargo Binaries Updated

The cargo install-update command (often referred to as “cargo update-install”) comes from the cargo-update plugin crate.

# install plugin providing cargo install-update
cargo install cargo-update

# update one installed binary crate
cargo install-update eza

# update all installed binary crates
cargo install-update -a

Cargo Common Workflow

# create a new binary project
cargo new hello-rust
cd hello-rust

# fast compile checks (without producing final binary)
cargo check

# build executable
cargo build

# run executable
cargo run

Before release, run the standard checks below.

Standard Quality Checks

# format check (requires rustfmt component)
cargo fmt --check

# lints (requires clippy component)
cargo clippy --all-targets --all-features -- -D warnings

# tests
cargo test

# docs (no deps)
cargo doc --no-deps

Publish a Crate

# log in to crates.io (one-time on a machine)
cargo login

# package sanity check
cargo package
cargo publish --dry-run

# publish to crates.io
cargo publish