Installing Rust and Cargo
Getting the Rust toolchain running through rustup, and what Cargo actually does for you.
2 min read
Rust is installed through rustup, a toolchain manager rather than a single installer. Rustup handles installing the compiler, keeping it updated, and switching between stable, beta, and nightly releases — you'll almost never interact with the compiler directly.
Installing rustup
On macOS and Linux, run the official install script:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shOn Windows, download and run rustup-init.exe from rustup.rs. Either way, once it finishes, restart your terminal and confirm both tools are on your PATH:
rustc --version
cargo --versionrustc is the compiler. cargo is the tool you'll actually use day to day.
What Cargo does
Cargo is Rust's build tool and package manager, rolled into one — closer to npm plus a build script than anything in C or C++. It handles four jobs:
- Building your code (
cargo build) - Running your code (
cargo run) - Testing your code (
cargo test) - Managing dependencies, called crates (declared in
Cargo.toml, downloaded from crates.io)
You will almost never invoke rustc by hand once a project exists — Cargo wraps it and adds dependency resolution, incremental compilation, and reproducible builds on top.
Creating a project
cargo new hello_rust
cd hello_rustThis scaffolds a small project:
hello_rust/
├── Cargo.toml
├── Cargo.lock
└── src/
└── main.rs
Cargo.toml is the manifest — project metadata and dependencies, similar to package.json:
[package]
name = "hello_rust"
version = "0.1.0"
edition = "2021"
[dependencies]src/main.rs is your entry point, pre-filled with a working "Hello, world!" program. Cargo.lock records the exact dependency versions actually used, so builds stay reproducible across machines — you shouldn't edit it by hand.
Building and running
cargo runcargo run compiles the project (if anything changed) and runs the resulting binary in one step. During development that's almost always the command you want. cargo build compiles without running, and cargo build --release produces a fully optimized binary — much slower to compile, much faster to execute — for anything you're actually shipping.
From here on, every lesson in this course assumes a Cargo project. Editors like VS Code with the rust-analyzer extension will give you inline error messages and autocomplete based on the same compiler, which is worth setting up before you go much further — Rust's compiler errors are genuinely useful, and seeing them as you type rather than only at cargo build will save a lot of round-trips.
Test what you just learned
4 quick questions. Get all of them right to unlock the next lesson.
You can take the quiz without an account — logging in just lets your result count toward your progress.