Install and Use Rust Programming Language on Rocky Linux 8

In this guide from the Linux Tutorials, we want to teach you to Install and Use Rust Programming Language on Rocky Linux 8.

A general-purpose programming language that focuses more on safety and concurrency and whose syntax is similar to C++ is called Rust programming language. It has high performance when compared with other programming languages and maintains memory safety features.

It also provides high system integrity. Rust is a new programming language, and the typing style is static. This language has many features such as safety, memory, and concurrency. The language is efficient and straightforward in style. Built-in macros are highly efficient. The language is designed to write system software. Rust is designed for system programmers.

Install and Use Rust Programming Language on Rocky Linux 8

To install Rust programming language, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide the Initial Server Setup with Rocky Linux 8.

Set up Rust on Rocky Linux 8

First, you need to install the Epel repository on your server with the following command:

sudo dnf install epel-release

Then, you need to install the required packages for the Rust language on your server with the command below:

sudo dnf install cmake gcc make curl -y

Now you can use the curl command to download the Rust installer script:

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

At this point, you need to start the Rust environment on Rocky Linux 8 with the following command:

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

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

rustc -V
Output
rustc 1.61.0 (fe5b13d68 2022-05-18)

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

How To Use Rust Programming Language

At this point, we want to show you how to use Rust on Rocky Linux 8 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 Rocky Linux 8, run the program with the execute command:

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

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.59.0 (9d1b2106e 2022-02-23)

info: cleaning up downloads & tmp directories

If you no longer want to use Rust on Rocky Linux 8, 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)

When you removed Rust, you will get the following output:

Output
info: removing rustup home
info: removing cargo home
info: removing rustup binaries
info: rustup is uninstalled

Conclusion

At this point, you learn to Install and Use Rust Programming Language on Rocky Linux 8.

Hope you enjoy using it.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!