Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
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.

Installing Rust and Cargo

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.

The shortcut

Think of the commands as a ladder, each step doing a little more: check → build → run → release. Climb only as high as you need.

A morning on the library programStep 1 of 4
  1. Editing

    You change a function and want to know if it compiles. cargo check answers in a moment.

The trap is timing speed with a debug build. Debug builds skip most optimisation, so they can be many times slower than --release.

Drills

Answer fast — trust the rule.

quick drill

Which tool installs Rust and later updates it to a new version?

quick drill

Which command gives the fastest "does it compile?" answer while editing?

quick drill

Where does the package's name, version and dependency list live?

quick drill

Your program seems slow. What should you do before measuring it?

Remember

  • rustup installs and updates rustc, cargo and the standard library.
  • Ladder: cargo check → cargo build → cargo run → cargo build --release.
  • Trap: measuring speed on a debug build.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainFrom nothing to a running program

A friend has a new laptop and wants to start the library program. List the commands they run, in order, from installing Rust to seeing output, and explain what cargo check is for.