Rust program basics | Creating a "Hello, World!" Program on Linux

In this blog post, we are going to see,  Rust program basics creating a hello world program on Linux. 

rust-program-basics-creating-hello-world-program


These are the details of the system which we used to create this content. 

linux-system-used-hello-world-program


Here we are going to see,

1.Project directory setup. 

2.Create a file for hello world program.

3.Compile and run file. 

hello-world-rust-program-creation-steps

Project directory setup:

In this particular content the meaning for folder and directory is same. Project directory setup helps to keep workspace clean in system (i.e., computer.)

First we are going to create a new directory in home called rust_projects.

create-directory-rust_projects-at-home-hello-world-rust-linux

Next inside rust_projects directory we are going to create a new directory called hello_world.

create-sub-directory-hello_world-rust_projects


So we can also call hello world directory is one of sub-directory of rust_projects directory.

Let we start to create this directories using a terminal. Open your terminal and enter the following commands. The commands to create rust_projects directory is 

mkdir rust_projects

Next let we go to rust_projects directory. The command to do this is the 

cd rust_projects

Next, let we create hello_world directory. The command is 

mkdir hello_world

Now let we go to hello_world directory.The command is 

cd hello_world

In the  hello_world directory , Create a file for hello world program. I am using VS Code. In the hello world_directory, create a file and save it as main. rs

in the name main.rs, rs is the file extension of rust. Now open the main.rs file and enter the code

as shown below. Save it again. 

fn main(){

    println!("Hello World!");

}


Now return to the terminal and go to hello world directory.

Enter the following commands to compile and run the file. 

rustc main.rs

Enter again.

Now rust will compile the code . 

Next type,

./ main in the terminal . Be sure you are running the command in hello_world directory.

Now will be printed.


Comments

Popular posts from this blog

How to install and uninstall standalone rust installer on Linux

Install rust on linux computer through rust up installer