Lesson 1: Getting Started

Installation

To install Rust:

Verify installation with rustc --version. Update with rustup update; uninstall with rustup self uninstall.

Hello, World!

To create and run a simple "Hello, world!" program:

  1. Create a project directory (e.g., mkdir ~/projects/hello_world on Linux/macOS).
  2. Create main.rs with:
fn main() {
    println!("Hello, world!");
}
  1. Compile: rustc main.rs.
  2. Run: ./main (Linux/macOS) or .\main.exe (Windows). Output: Hello, world!

Introduction to Cargo

Cargo is Rust's build system and package manager. Verify with cargo --version.

Create a project: cargo new hello_cargo. This generates Cargo.toml and src/main.rs.

Build: cargo build (executable in target/debug/).

Run: cargo run (builds and runs in one step).

Check compilation: cargo check. For release: cargo build --release.

You Try

Edit the code below to print a different message, then click Run to compile and execute it.

fn main() {
    println!("Hello, world!");
}