Part-1: Getting Started with Rust🦀
Tags: rust, programming, tutorial, learning
Published: 2024-01-18 17:01:47

Hey folks, this is part-1 of my new blog series on rust. In this blog series i'll teach you about rust programming language and why you should learn it in 2024.

So without wasting any time lets get started!

# Why Rust?

Rust has a minimal runtime and control over memory layout makes it incredibly useful for developing embedded systems and Internet of Things (IoT) devices. Now these are some benefits of rust which i also saw on google. But why you should learn rust? As everyone know more than 95% of the websites are build using JS then why even bother learning rust. So first everyone today knows JS, its so common and due to that beginners face difficulty in finding jobs using JS. 

On the other hand, rust's job market is not that big and there are not much jobs as compared to JS but the market is rust is growing very fast. And Rust has been the fav language of developers for years. And i personally believe that Rust is the option you should go for if you're already familiar with JS and want to level up your career.

Now some people might get offended and say that Rust will never replace JS and stuff like that, but i believe that if you want to level up then you have to do something which others are not doing.

With this lets start our rust journey!

Also one more last thing in this series i'll be telling commands for linux or macOs, you can always google things to find similar command for windows(this is a good practice learn how to google things).

---

# Getting Started

To setup rust on your machine you need to download a script and install the rustup tool which basically installs the latest version of rust on your maching. If you’re using Linux or macOS, open a terminal and paste the following command:

```
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
```

If the install is successful, the following line will appear: 

```
Rust is installed now. Great!
```

> Restart your system other rust won't work(it didn't worked for me!)

Now everything is set, and you are ready to write your most important program in Rust, if you guessed it, yes it is your `Hello World!` program in rust.

---

# Writing your first `Hello World!` program in Rust

Start by making a directory to store your Rust code.

Open a terminal and enter the following commands to a projects directory and a directory for hello world program

```
$ mkdir ~/projects
$ cd ~/projects
$ mkdir hello_world
$ cd hello_world
```

Now open your favourite code editor in this `hello_world` directory and make a file called `main.rs` (you can name it whatever you want) and paste the following code.

```
fn main() {
    println!("Hello, world!");
}
```

This is basically a function called main, which is just printing a string `Hello, world!` in the console.

I'll explain each and every thing in detail as we go along, just be with me for some time.

Now open your terminal(make sure you are in the same directory where your main.rs file lives) and run the following commands:

```
$ rustc main.rs
$ ./main
Hello, world!
```

When you run `rustc main.rs` then it will create a binaries file called `main`. And when you run `./main` then it will simply execute that binary and run the code.

---

# Congratulations

Thats it you've written your first program in rust. You are now 1 step closer to becoming a rust expert. I'll explain each and eveything we did today, in the upcoming blogs.

Stay tuned for upcoming blogs, and remember every good thing takes time. I'll see you guys in the next one, Till then!

Happy Coding!

---

You can find me on twitter [here](https://twitter.com/yadav_bhavesh73) .

---