Rust is a programming language with three key design tenets: safety, concurrency, and practicality. It is an open-source project that aims for speed, memory safety, and parallelization.

It was created by Graydon Hoare in 2010. It is now developed mainly by the Rust Project Developers with help from the community with the goal of creating a modern system programming language that guarantees thread safety, complete control over the lifecycle of memory, and efficient C bindings. Rust is a statically typed programming language, and it uses type inference to make sure you do not need to redundantly specify your types.

Rust was created as an alternative to C /C that makes it possible to write safe code without worrying about memory or thread issues.

There are several benefits to using Rust over C/C , including improved memory safety and higher performance. With its focus on zero-cost abstractions, it is easy to learn, develop, master, and deploy.

Rust has a simple programming model. zit is easy to learn for beginners and at the same time provides advanced features like zero-cost abstractions, traits, pattern matching, guaranteed memory safety through its ownership system, automatic memory management through its unique garbage collection algorithm, and thread-safe concurrency with message passing between threads.

In this article, we will learn how to install Rust on an AlmaLinux 8 system. This tutorial includes detailed instructions along with screenshots of the steps in the process. 

Prerequisites

  • A server running AlmaLinux 8 x64.
  • A user account with sudo privileges.

Updating the System

We need to update the system before installing Rust because of two reasons. First, it is important to keep the system up-to-date for security purposes and second, it can be necessary in order to make sure that Rust will work properly. Run the following command to update the system.

sudo dnf check-update
sudo dnf update -y
sudo dnf upgrade -y

After the update process is finished, we will need to install the required dependencies. Run the following command to install Rust dependencies.

sudo dnf install epel-release
sudo dnf install cmake gcc make curl -y

Installing Rust Programming Language

Now that our system is up-to-date and we have installed all the necessary dependencies, we can proceed with installing Rust programming language on our system. We will use curl to download a script that will install the latest version of the compiler. Run the following command in order to download and execute it.

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

The installation script will take a while to finish. The script will automatically install the required dependencies and rust itself. After this process is finished, we need to add rustup bin directory to our PATH variable in order to use rustc and other tools supplied by Rust. Run the following command to set up the environment variables.

source ~/.profile
source ~/.cargo/env

After finishing the installation process, we can check if rust is installed correctly by running the rustc command with the -V flag.

rustc -V

You should get an output similar to the following screenshot. You can see the version of the Rust language that we have installed. Your version may be different than the one in this example.

<img alt="rustc -Version" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/rustc_version.png6177dda89ff00.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="54" loading="lazy" src="data:image/svg xml,” width=”656″>

Testing the Rust Installation 

Now that we have installed Rust on our AlmaLinux system, we will create a simple project that will be used to test the Rust installation.

First, create a directory for our example project. We will name the directory rust-example. We will create this folder inside our home directory. Run the following command in order to create a new rust project inside your home directory.

cd && mkdir rust-example

After creating the new directory for our project, we need to change the current working directory to the newly created rust-example directory. Run the following command to change the directory.

cd rust-example

There are a number of different projects that we can create with Rust. We will create a simple “Hello world” project in this article. Run the following command to generate a new Rust application named hello_world.

sudo nano hello_world.rs

We need to add the code that will print “Hello world!” to the command line. The following lines are the content of the hello_world.rs file.

fn main() {
  println!("Hello World, Howtoforge");
}

The first line defines a new function named main. We will use the main function as an entry point for this application. The second line starts a block of code that will be executed when we run the application. This defines a new variable named println and assigns the string “Hello World, Howtoforge” to this variable. In the end, we need to close (} and ( )) the code block to indicate the end of the println function.

After completing this step, we need to save and exit from the editor by pressing Ctrl X. We will be prompted to save the file or not. You can enter Y and hit Enter to indicate that you want to save this file. That will close the hello_world.rs file and return us back to the command-line prompt.

Now that we have our application created, we can compile it into a binary file by running rustc command with the file name as a parameter. The following command will compile the hello_world.rs file into a binary named hello_world .

rustc hello_world.rs

You can run the ls command to list all files in the current directory. You should see a binary file named hello_world under the rust-example directory.

ls

<img alt="Testing the Rust Installation" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/testing_the_rust_installation.png6177dda8c106a.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="52" loading="lazy" src="data:image/svg xml,” width=”659″>

We can execute our program by printing the path to the executable file and providing it as an argument to the ./hello_world command.

./hello_world

You should get an output similar to the following screenshot on your command line. Congratulations, you have successfully run your first Rust program.

<img alt="Testing the Rust Installation" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/testing_the_rust_installation_2.png6177dda8e4697.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="46" loading="lazy" src="data:image/svg xml,” width=”653″>

Conclusion

In this article, we have learned how to install Rust language on our AlmaLinux system. We have also created a  sample project that can be used to test the Rust installation. Please leave us any comment if you have a problem with the installation process, or something is not working correctly.