Rust: A Beginner's Guide to Installation and Writing Your First "Hello, World!" Program


Let's go through the steps to install Rust on your system and write your first "Hello, World!" program.
Visit the Rust Website:
Go to the official Rust website: https://www.rust-lang.org/.
Click on the "Get Started" button.
Download the Installer:
- For Windows, download the
rustup-init.exe
file.
- For Windows, download the
Run the Installer:
Open the downloaded
rustup-init.exe
file.Follow the on-screen instructions. Press
1
to proceed with the default installation.
Verify the Installation:
Open a new terminal or command prompt.
Run the following command to check if Rust is install
rustc --version
Install dependencies rust-analyzer
2. Writing Your First Rust Program: "Hello, World!"
Create a New Project:
Open a terminal or command prompt.
Use
cargo
(Rust's build system and package manager) to create a new project:cargo new hello_world cd hello_world
This will create a new directory called
hello_world
with a basic Rust project structure.
Explore the Project Structure:
The
src
folder contains your Rust code.Open the
src/
main.rs
file. It will already have a "Hello, World!" program:fn main() println!("Hello, world!"); }
Run the Program:
In the terminal, run the following command to compile and execute the program:
cargo run
You should see the output:
Hello, world!
3. Understanding the Code
fn main() { ... }
: This defines themain
function, which is the entry point of every Rust program.println!("Hello, world!");
: This macro prints the textHello, world!
to the console.
Subscribe to my newsletter
Read articles from Anish sharma directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
