EN | DE

Stage 2.8: Writing A Hello World Program

You can create a new file main.rs and put the code from the Rust Playground in it
or you can use cargo to create a new project with either cargo new hello-world or cargo init

cargo will automatically create a src/main.rs for you which already has a Hello, world! output in it.

If you chose cargo to create a basic project for you, all you have to do is to run: cargo run in a terminal and you should see the output: Hello, world!

If you created a main.rs without cargo, you have to use the Rust compiler rustc and run: rustc main.rs.
This will create a main.exe in the same directory. Now you have to execute this compiled file (./main.exe) and you will see the same output.

In a later lesson you will also learn how to split your code into multiple files.

Share on Facebook Share on Twitter Share on Reddit Save on Pocket Share on LinkedIn Share via email