Your First 'Hello, World!'
Write and run your very first 'Hello, World!' program in Rust. Understand the basic compilation and execution process.
Your First 'Hello, World!' is a free Learn Rust Coding lesson on CoddyKit — lesson 2 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Learn Rust Coding learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Your First Rust Program
Time to write your first Rust program: Hello, World! It's the classic way to confirm your setup works and meet the basics.
Creating Your Source File
Rust source files end in .rs, like main.rs. Create one in a fresh project folder — this holds the instructions you write.
The `fn main()` Function
Every Rust program starts in a function called main. The fn main() { } syntax declares it: fn for function, then a name, params, and a body.
Printing to the Console
To print to the console, use the println! macro. The ! marks it as a macro — code that expands at compile time. Pass your text in quotes and end with ;.
Your "Hello, World!" Code
Here's the full Hello, World! program. Drop it into main.rs — note the semicolon ending the println! statement.
fn main() {
println!("Hello, world!");
}Turning Code into an Executable
Your CPU can't read Rust directly, so the compiler rustc translates it. Run rustc main.rs to produce an executable.
rustc main.rsExecuting Your Program
Now run the executable: ./main on Linux/macOS or main.exe on Windows. You'll see your greeting — compile, then run.
./mainUsing Cargo for Convenience
Plain rustc works, but most projects use Cargo to scaffold, build, and run — especially as things grow. It sets up a standard layout for you.
Cargo's Hello World
Spin up a project with cargo new, then cd in and cargo run. Cargo compiles and runs in one step, handling the details.
fn main() {
println!("Hello, world!");
}Compiling & Running
You've written your first Rust program and learned two ways to run it: directly with rustc and using Cargo. Let's check your understanding.
Recap: Your First Rust Program
You created, compiled, and ran your first program — both with raw rustc and the smoother cargo run. Next, the full toolchain.
Frequently asked questions
Is the “Your First 'Hello, World!'” lesson free?
Yes — the full text of “Your First 'Hello, World!'” is free to read here on the web, and the Learn Rust Coding course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Learn Rust Coding course, upgrade to CoddyKit PRO.
What will I learn in “Your First 'Hello, World!'”?
Write and run your very first 'Hello, World!' program in Rust. Understand the basic compilation and execution process. You practise Learn Rust Coding with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Learn Rust Coding?
No prior experience is required. Learn Rust Coding on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 3, so you can start here or from the beginning and move at your own pace.
How long does the “Your First 'Hello, World!'” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Learn Rust Coding lesson?
Yes. Every Learn Rust Coding lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Installing Rust and Cargo
- Your First 'Hello, World!'
- Exploring the Rust Toolchain