Lesson 1 of 12

Hello, World!

Write and run your first Rust program, and learn how to print values with println! and create projects with Cargo.

Every Rust program starts with a main() . Rust files have the .rs extension. The rustc compiles your file to a native — no virtual machine, no .

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

println! is a macro (the ! tells you so). Macros in Rust are more powerful than functions — they can take a number of and generate code at compile time. You'll use println! constantly for .

Rust
fn main() {
    // Simple string
    println!("Hello, World!");

    // Formatted output — {} is a placeholder
    let name = "Alice";
    let age = 30;
    println!("Name: {}, Age: {}", name, age);

    // Named placeholders
    println!("{name} is {age} years old.");

    // Debug format — prints almost anything with {:?}
    let numbers = vec![1, 2, 3, 4, 5];
    println!("{:?}", numbers);   // [1, 2, 3, 4, 5]
    println!("{:#?}", numbers);  // pretty-printed

    // eprintln! prints to stderr
    eprintln!("This goes to stderr");
}

To compile and run: rustc hello.rs && ./hello. For any real project, use Cargo — Rust's build system and . cargo new my_project creates a project, cargo run compiles and runs it.

Bash
cargo new hello_world
cd hello_world
cargo run
Finished reading?Mark it done to track your progress.

Tip: use the ← and → keys to move between lessons.