How To Install Rust Programming Language on AlmaLinux 9

In this guide, you will learn How To Install Rust Programming Language on AlmaLinux 9 and create a sample project with it.

Rust was created to ensure high performance similar to that offered by C and C++,  but with emphasis on code safety, the lack of which is the Achilles heel of these two languages. However, Rust has more than just memory safety on its side.

High performance while processing large amounts of data, support for concurrent programming, and this together with an effective compiler are other reasons why well-known software heavyweights now use this programming language. Firefox, Dropbox, Cloudflare, and many other companies from startups to large corporations use Rust in production. 

Steps To Install Rust Programming Language on AlmaLinux 9

To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with AlmaLinux 9.

Now follow the steps below.

Install Rust on AlmaLinux 9

First, you need to update your local package index with the following command:

sudo dnf update -y

Then, install the Epel repo on your server by using the command below:

sudo dnf install epel-release -y

Install Dependencies for Rust Language

Now use the following command to install the required packages and dependencies:

sudo dnf install cmake gcc make curl -y

Download Rust Installer Script

At this point, you need to download the Rust installation script on your AlmaLinux 9 by using the command below:

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

In your output you will see:

Output
Current installation options:


   default host triple: x86_64-unknown-linux-gnu
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>1

Enter 1 to proceed with the default installation.

When your installation is completed, you will get the following output:

Output
stable-x86_64-unknown-linux-gnu installed - rustc 1.65.0 (897e37553 2022-11-02)


Rust is installed now. Great!

Start Rust Environment

At this point, you need to start the Rust environment on AlmaLinux 9 with the following command:

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

To verify that Rust programming language is installed successfully on your server, run the command below:

rustc -V
Output
rustc 1.65.0 (897e37553 2022-11-02)

Now that you have Rust installed on your server, let’s see how to use it.

Create a Sample Project with Rust Language

At this point, we want to show you how to use Rust on AlmaLinux 9 by creating a new sample protect hello world.

First, you need to create a directory for your Rust project with the command below:

mkdir rust-projects

Then, switch to your Rust project directory:

cd rust-projects

Now you need to create a sample application with your favorite text editor, here we use vi:

vi helloworld.rs

Add the following content to the file:

fn main() { 
println!("Hello World, this is a test provided by orcacore.com"); 
}

When you are done, save and close the file.

Now compile the program with the following command:

rustc helloworld.rs

This will create an executable application after it has finished compiling.

To run the application you created using Rust on AlmaLinux 9, run the program with the execute command:

./helloworld
Output
Hello World, this is a test provided by orcacore.com

Update Rust Programming Language

Also, you can update your Rust programming language with the following command:

rustup update
Output
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: checking for self-updates

  stable-x86_64-unknown-linux-gnu unchanged - rustc 1.65.0 (897e37553 2022-11-02)

info: cleaning up downloads & tmp directories

Remove Rust Programming Language

If you no longer want to use Rust on AlmaLinux 9, you can easily remove it with the following command:

rustup self uninstall
Output
Thanks for hacking in Rust!

This will uninstall all Rust toolchains and data, and remove
$HOME/.cargo/bin from your PATH environment variable.

Continue? (y/N)

For more information, you can visit the Rust by Example page.

Conclusion

At this point, you have learned to Install Rust Programming Language on AlmaLinux 9 and create a sample project by using Rust.

Hope you enjoy it.

You may be like these articles:

Install Apache Cassandra on AlmaLinux 9

How To Enable TCP BBR on AlmaLinux 8

How To Set up Golang on Debian 11

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!