Getting Started with Rust: Your First ‘Hello World’ Program
In this article, we will walk through writing a ‘Hello World’ program in Rust, exploring syntax, setup, and fundamental Rust programming basics.
As we learned in our previous lesson, Rust is a compiled language. This means that before we can execute a Rust program, it must first be compiled into machine code, which allows it to run natively on the device.
Every Rust installation includes a built-in compiler to handle this process, which can be accessed via the rustc
command. For example, when I run $ rustc -V
on my machine, it displays the version information of the Rust compiler.
rustc 1.81.0 (eeb90cda1 2024-09-04)
If you do not see an output like this, please refer to this troubleshooting guide.
A normal Rust program ends with .rs
extension. For the “Hello World” program, let’s create a hello_world.rs
file in a directory. It is idiomatic to _
(underscores) in the file name than _
(hyphens). Open this file with your faviourite IDE or code editor and paste the following content.
fn main() {
println!("Hello, world!");
}