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

Anish sharmaAnish sharma
2 min read

Let's go through the steps to install Rust on your system and write your first "Hello, World!" program.

  1. Visit the Rust Website:

  2. Download the Installer:

    • For Windows, download the rustup-init.exe file.
  3. Run the Installer:

    • Open the downloaded rustup-init.exe file.

    • Follow the on-screen instructions. Press 1 to proceed with the default installation.

  4. Verify the Installation:

    • Open a new terminal or command prompt.

    • Run the following command to check if Rust is install

    • rustc --version

  5. Install dependencies rust-analyzer

2. Writing Your First Rust Program: "Hello, World!"

  1. 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.

  2. 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!");
        }
      
  3. 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 the main function, which is the entry point of every Rust program.

  • println!("Hello, world!");: This macro prints the text Hello, world! to the console.

10
Subscribe to my newsletter

Read articles from Anish sharma directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Anish sharma
Anish sharma