Phase 1Getting started

#1 Installing Rust

rustup, cargo, rustc

What is Rust?

Rust is a systems programming language focused on safety, speed, and concurrency. It prevents common bugs like null pointer dereferences and data races at compile time, without needing a garbage collector.

Rust is used for web servers, command-line tools, embedded systems, WebAssembly, and much more. Companies like Mozilla, Google, Microsoft, and Amazon use Rust in production.

Install with rustup

The recommended way to install Rust is through rustup, the official Rust toolchain installer. It manages Rust versions and associated tools for you.

On Linux or macOS, run this command in your terminal:

Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

On Windows, download and run rustup-init.exe from rustup.rs. The installer will guide you through the setup.

After installation, restart your terminal (or run source $HOME/.cargo/env) so the new commands are available.

Verify installation

Once installed, verify everything works by checking the versions of the three main tools:

Check versions
$ rustup --version
rustup 1.27.1 (54dd3d00f 2024-04-24)

$ rustc --version
rustc 1.78.0 (9b00956e5 2024-04-29)

$ cargo --version
cargo 1.78.0 (54d8815d0 2024-03-26)

rustup is the toolchain manager, rustc is the Rust compiler, and cargo is the build system and package manager.

To update Rust to the latest version at any time, simply run rustup update.

Cargo — your toolbox

Cargo is the heart of the Rust ecosystem. It handles:

What Cargo does
cargo new my-project   # Create a new project
cargo build            # Compile your project
cargo run              # Compile and run
cargo test             # Run tests
cargo check            # Check code without building
cargo doc              # Generate documentation

Cargo also manages dependencies (called crates) through the Cargo.toml file. You can find thousands of crates on crates.io, the Rust package registry.

Your turn

Try checking the Rust toolchain versions in the terminal below. Run rustup --version, rustc --version, and cargo --version:

terminal — bash
user@stemlegacy:~$