Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Setting up Rust and Cargo | Rust Fundamentals lesson | BraveProgrammer
  1. Courses
  2. /
  3. Rust Fundamentals

Lesson 2 of 50

·rust

Setting up Rust and Cargo

20 minutes

Course progress4%

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 documentation
  • Sets up your PATH environment variable
  • Verify installation:

    rustc --version  # Rust compiler version
    cargo --version  # Package manager version
    rustup --version # Version manager
    

    Updating Rust

    Rust releases stable versions every 6 weeks. Keep updated:

    rustup update
    rustup toolchain list  # See installed toolchains
    rustup install nightly # Install nightly builds
    rustup default stable  # Set default toolchain
    

    Creating Your First Project

    cargo new hello_world --bin  # Binary project
    cargo new my_lib --lib      # Library project
    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              # Debug build
    cargo build --release   # Optimized release build
    cargo run               # Build and run
    cargo check             # Verify without building binary
    cargo test              # Run tests
    cargo fmt               # Auto-format code
    cargo clippy            # Linter for improvements
    cargo doc --open        # Generate & open documentation
    

    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
    Previous lessonIntroduction to RustContinue to lesson 3Your First Program (Hello World)Back to Rust Fundamentals curriculum