← All notes

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

Claims

Sources

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.

License: CC-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.

Cite this

Permanent ID: iil:note:5gh1a4zw

iinventedlight. 2026. "Rust book: write, compile, and run a Hello, world! program." iinventedlight Library, iil:note:5gh1a4zw, version of 2026-11-27. https://iinventedlight.com/library/notes/rust-hello-world/. License: CC-BY-4.0.

@misc{iil_note_5gh1a4zw,
  author = {{iinventedlight}},
  title = {{Rust book: write, compile, and run a Hello, world! program}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-27},
  url = {https://iinventedlight.com/library/notes/rust-hello-world/},
  note = {Permanent ID iil:note:5gh1a4zw. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/rust-hello-world.md.