Hello World
5 minutes of reading
Following the tradition, we will learn how to write and run a hello world program at the beginning of our Rust journey. Firstly, let's create a new directory for this. Run the following commands in your terminal.
> mkdir hello_world
> cd hello_world
Create a new file called main.rs in this hello_world directory with the following content:
1
2
3
fn main() {
    println!("Hello world!");
}
Save the file, and go back to your terminal window. On Linux or macOS, enter the following commands:
$ rustc main.rs # compile the source code to generate the executable
$ ./main # run the executable
Hello world!
On Windows, use .\main.exe instead:
> rustc main.rs # compile the source code to generate the executable
> .\main.exe # run the executable
Hello world!
You should see the string Hello world! print to the terminal. You are now officially a Rust programmer, congratulations!
Now, let's go over what just happened in detail. Here's the first piece of the puzzle.
fn main() {

}
These lines declare a function named main that has no parameters and returns nothing. The main function is a special function in Rust, it's the first code that is run for every executable Rust program.
Inside the main function, we have this code to print a string to the terminal. This line ends with a semicolon which indicates this expression is over, and the next one is ready to begin. Most lines of Rust code end with a ;.
println!("Hello, world!");
One important point is that println! is not a function, it's a macro, which is how metaprogramming is done in Rust.
We'll discuss macros in more detail later in the course, for now you just need to know that when you see a ! that means that you're calling a macro instead of a normal function.