---
source: https://iinventedlight.com/library/notes/rust-hello-world.md
title: "Rust book: write, compile, and run a Hello, world! program"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT OR Apache-2.0 (The Rust Project Developers); MIT OR Apache-2.0 (The Rust Project Developers); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: The Rust Project Developers, Hello, World!; The Rust Project Developers, Hello, World! (source). MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-27
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-27
as_of: 2026-11-27
confidence: medium
untested: "Not reproduced (2026-11-27). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: rust-hello-world"
tags: [rust, hello-world, rustc, main, println]
client: Librarian
sources:
  - id: S1
    title: "Hello, World!"
    publisher: The Rust Project Developers
    url: https://doc.rust-lang.org/book/ch01-02-hello-world.html
    accessed: 2026-11-27
    license: "MIT OR Apache-2.0"
  - id: S2
    title: "Hello, World! (source)"
    publisher: The Rust Project Developers
    url: https://raw.githubusercontent.com/rust-lang/book/main/src/ch01-02-hello-world.md
    accessed: 2026-11-27
    license: "MIT OR Apache-2.0"
---
# Rust book: write, compile, and run a Hello, world! program
**Answer:** Now that you've installed Rust, it is time to write your first Rust program.

## A first project

Now that you've installed Rust, write your first Rust program in a hello_world directory under ~/projects, or %USERPROFILE%\projects on Windows CMD.

The source file is main.rs. Rust files always end with the .rs extension. If a filename has more than one word, the convention is to use an underscore.

The program is a main function that calls println! with Hello, world!. On Linux or macOS you compile with rustc main.rs and start the binary with ./main. On Windows the run command is .\main.

## What the program is doing

main is special: it is the first function that runs in an executable. This one takes no parameters and returns nothing. Parameters would be written inside the parentheses.

The body sits in curly brackets. It is good style to place the opening curly bracket on also the same line as the function declaration, with one space in between.

This line prints text. It is a Rust macro, not a function; a function would be written println without the !. A ! means you are calling a macro, and macros don't always follow the same rules as functions.

## Compile, then run

You compile first with rustc and the file name, such as rustc main.rs.

You then run ./main or .\main on Windows.

## See also

- [rust-hello-cargo](https://iinventedlight.com/library/notes/rust-hello-cargo/)
- [rust-functions](https://iinventedlight.com/library/notes/rust-functions/)
- [rust-comments](https://iinventedlight.com/library/notes/rust-comments/)

## Claims

- id: C1
  claim: Rust source files use the .rs suffix.
  source: S2
  evidence: "Rust files always end with"

- id: C2
  claim: main is the first function that runs in an executable.
  source: S1
  evidence: "always the first code that runs in every executable"

- id: C3
  claim: println! is a macro, not a function.
  source: S2
  evidence: "you're calling a macro instead of a normal"

- id: C4
  claim: rustc main.rs writes a binary executable.
  source: S1
  evidence: "rustc main.rs"

- id: C5
  claim: Rust is compiled ahead of time.
  source: S2
  evidence: "ahead-of-time compiled"

## Sources

- [S1] Hello, World!. The Rust Project Developers. https://doc.rust-lang.org/book/ch01-02-hello-world.html . License: MIT OR Apache-2.0. Accessed 2026-11-27.

- [S2] Hello, World! (source). The Rust Project Developers. https://raw.githubusercontent.com/rust-lang/book/main/src/ch01-02-hello-world.md . License: MIT OR Apache-2.0. Accessed 2026-11-27.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Rust Project Developers, Hello, World!; The Rust Project Developers, Hello, World! (source). MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
