Skip to main content Setting up Rust and Cargo | Rust Fundamentals lesson | BraveProgrammerSetting up Rust and Cargo
20 minutes
Setting up Rust and Cargo
Rust provides rustup (version manager) and cargo (package manager and build system). Together, they handle everything needed to build Rust applications.
Installation (macOS, Linux, Windows WSL)
Rust provides a simple installation script:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
This script automatically:
- Downloads the appropriate Rust toolchain for your OS
Installs rustup, cargo, rustc, and documentationSets up your PATH environment variablerustc --version
cargo --version
rustup --version
Updating Rust
Rust releases stable versions every 6 weeks. Keep updated:
rustup update
rustup toolchain list
rustup install nightly
rustup default stable
Creating Your First Project
cargo new hello_world --bin
cargo new my_lib --lib
cd hello_world
Generated Structure
hello_world/
├── Cargo.toml # Project manifest
├── Cargo.lock # Dependency lock file
└── src/
└── main.rs # Entry point
Building and Running
cargo build
cargo build --release
cargo run
cargo check
cargo test
cargo fmt
cargo clippy
cargo doc --open
Debug builds compile faster but run slower. Release builds take longer but produce significantly faster binaries.
Make it stickPractice what you've learned1 quiz · 1 practical test · Optional activities from Rust FundamentalsBrowse activities