Hello World in Rust
In this article, we have explained step by step how to create and run Hello World code in Rust. We have added the steps to install Rust compiler and related tools as well.
Table of contents:
- Install Rust compiler and tools
- Hello World in Rust
Let us get started with Hello World code in Rust Programming Language.
Install Rust compiler and tools
Install Rust on Linux / Ubuntu as follows:
curl https://sh.rustup.rs -sSf | sh
The above command will download rustup-init.sh file on your system and run it which will install all essential Rust tools include rustc which is the Rust compiler.
To install Rust on Windows, download rustup-init.sh file at following URL:
https://static.rust-lang.org/rustup/dist/i686-pc-windows-gnu/rustup-init.exe
Once downloaded, double click the rustup-init.exe file and all Rust tools will be installed.
Hello World in Rust
Follow the following steps to create and run Hello World code in Rust:
- Create a new file and name it as "hello.rs". All Rust code has an extension .rs.
- Edit the file and add the following code in it:
// Hello World code in Rust
fn main() {
println!("Hello World");
}
This above code is the Hello World code in Rust. It will simply print "Hello World" in the terminal.
-
Go to the terminal and go to the directory where your code hello.rs is stored.
-
Type the following command in the terminal.
rustc hello.rs
This will create an executable named hello.exe in the current working directory.
- Run the executable using the following command:
./hello.exe
The output will be displayed on the terminal. It will be:
Hello World
With this article at OpenGenus, you have the complete knowledge to write Hello World code in Rust. Enjoy learning the most promising Programming Language in the World.