Skip to the workspace
Pebellslearn by building
Language Basics  ›  Lesson

Installing Rust and Cargo

Installing Rust and Cargo 12 minrustup installs and updates the Rust toolchain, and Cargo creates, builds, runs and checks projects described by a Cargo.toml file.

rust / Installing Rust and Cargo

Explore each scene at your own pace.

01 · The rule

The rule

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 --version

Cargo 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 run

cargo new creates this layout:

shelf/
├── Cargo.toml       # the package: name, version, edition, dependencies
└── src/
    └── main.rs      # fn main() lives here

Cargo.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 into target/debug/.
  • cargo run: build if needed, then run.
  • cargo build --release: an optimised build in target/release/, slower to compile, faster to run.
Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.