Code of the Day
BeginnerCore syntax

Hello, World!

Install Rust, meet cargo, and run your first program end-to-end.

RustBeginner8 min read
By the end of this lesson you will be able to:
  • Install Rust with rustup and verify the installation
  • Create a new project with cargo new and understand the file layout
  • Write and run a program that prints to the terminal
  • Read a basic compiler error message without panicking

Every language has a ritual first program. Rust's is the same two words as everyone else's — but the toolchain you use to run it is one of Rust's genuine superpowers. Let's install it and see why.

Installing Rust

Rust is distributed through , a version manager similar to nvm for Node or pyenv for Python. One command covers Linux, macOS, and WSL on Windows:

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

Follow the prompts, then open a fresh terminal and verify:

rustc --version   # rustc 1.78.0 (something like that)
cargo --version   # cargo 1.78.0

rustup manages toolchains. Run rustup update whenever you want the latest stable Rust. Run rustup doc to open the official book offline — no internet required.

cargo new — your project scaffold

You will almost never write a bare rustc command. Instead, use , Rust's build system and package manager:

cargo new hello-world
cd hello-world

Cargo creates this structure:

hello-world/
├── Cargo.toml      # project metadata and dependencies
└── src/
    └── main.rs     # your program's entry point

Cargo.toml is Rust's equivalent of package.json or pyproject.toml. For now it just contains a name, version, and Rust edition. The only file you need to edit is src/main.rs.

The program

Open src/main.rs. Cargo already put the hello-world program there:

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

Three things to notice:

  1. fn main() is the entry point — every Rust executable starts here. This mirrors the fundamentals lesson on how programs begin execution.
  2. println! is a , not a function — the ! tells you that. Macros look like function calls but expand to more code at compile time. You'll use println! constantly.
  3. Statements end with a semicolon ;. This will matter more when we talk about expressions in the functions lesson.

cargo run

One command to compile and run:

cargo run

You should see:

   Compiling hello-world v0.1.0
    Finished dev [unoptimized + debuginfo] target(s) in 0.42s
     Running `target/debug/hello-world`
Hello, world!

Cargo compiled the project, then immediately ran it. During development, cargo run is the command you'll use most.

cargo build vs cargo run: cargo build compiles and puts the binary in target/debug/ without running it. cargo run builds and then executes. Both are fine — run is usually more convenient while you're developing.

Reading a compiler error

Rust's compiler is famously helpful. Try deliberately breaking the program — change println! to printlng! and run it again:

error[E0425]: cannot find function `printlng` in this scope
 --> src/main.rs:2:5
  |
2 |     printlng!("Hello, world!");
  |     ^^^^^^^^ not found in this scope
  |
  = help: did you mean `println`?

The format is always: error code, description, file and line number, an arrow to the exact spot, and often a suggestion. Rust errors are verbose on purpose — they're designed to teach you, not just stop you. Get comfortable reading them top-to-bottom.

Don't skip the error output. New Rust developers often see red text and scroll past it. The first error is almost always the real one; fix it, run again, and often later errors disappear. Read the help: and note: lines — they tell you what to do.

Do it yourself

After installing Rust, run these commands in sequence — type them, don't copy-paste:

cargo new my-first-project
cd my-first-project
cargo run

Then change the string inside println! to something personal and run it again. Seeing your own words in the terminal output is a small milestone worth earning.

Where to go next

You have a working Rust toolchain and a project structure that cargo will use for everything. Next: variables and types — how Rust names values, what types it knows about, and why the compiler wants to know the type of everything upfront.

Finished reading? Mark it complete to track your progress.

On this page