Installing Rust and Cargo
rustup installs and updates the Rust toolchain, and Cargo creates, builds, runs and checks projects described by a Cargo.toml file.
Install a toolchain and follow Cargo's check, build and run stages.
Before the library program can run anywhere, you need the compiler and the tool that drives it. Rust ships them as one bundle with a single installer, and after that one command creates a whole project for you.
The rule
rustup installs Rust; Cargo builds, runs and checks your project.
rustup is the official installer and version manager. It puts three things on your machine: rustc (the compiler), cargo (the build tool and package manager) and the standard library. Later, rustup update moves you to the newest release. Confirm the install with:
rustc --version
cargo --versionCargo is how you actually work day to day. You rarely call rustc yourself.
cargo new shelf # make a new project called shelf
cd shelf
cargo run # compile, then runcargo new creates this layout:
shelf/
├── Cargo.toml # the package: name, version, edition, dependencies
└── src/
└── main.rs # fn main() lives hereCargo.toml is written in TOML:
[package]
name = "shelf"
version = "0.1.0"
edition = "2021"
[dependencies]The everyday commands:
cargo check: run the compiler's checks, skip making the executable. Fastest feedback.cargo build: compile intotarget/debug/.cargo run: build if needed, then run.cargo build --release: an optimised build intarget/release/, slower to compile, faster to run.