How to Install Rust on Rocky Linux 9

Rust is a systems programming language focused on speed, memory safety, and parallelism. Rust is syntactically similar to C++ but can guarantee memory safety by using a borrow checker for validating references. Rust is backed by a large and friendly community of developers committed to improving the language. The Mozilla Foundation supports the Rust team, which ensures that the language remains free and open source. Rust is used in various software applications, such as game engines, operating systems, file systems, browser components, and simulation engines for virtual reality. Thanks to its focus on safety and performance, Rust has quickly become a popular choice among developers for many projects.

For some history of Rust programming language’s background, it was initially designed by Graydon Hoare at Mozilla Research. The language was launched in 2010, and its stability and GPU support makes it a popular choice for developers looking to create high-performance applications. Rust is used in various applications, such as game engines, operating systems, file systems, browser components, and simulation engines for virtual reality. In 2016, Rust was voted the “most loved programming language” in the Stack Overflow Developer Survey.

For users, especially developers wanting to try out Rust Programming language, you will know how to install Rust on Rocky Linux 9; the tutorial will teach you how to install the latest version with the official bash script.

Update Rocky Linux

First, before proceeding with the tutorial, update your system to ensure all packages are up-to-date to avoid any conflicts using the following command.

sudo dnf upgrade --refresh

Install the EPEL/EPEL Next Repository

The first task is to install the EPEL repository, and the recommendation is to install both repositories.



First, enable the CRB repository.

sudo dnf config-manager --set-enabled crb

Next, install EPEL using the following (dnf) terminal command.

sudo dnf install \
    https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm \
    https://dl.fedoraproject.org/pub/epel/epel-next-release-latest-9.noarch.rpm

Install Required Packages

Now with the EPEL repository installed, I recommend installing the following packages. These may be already installed but run the command to ensure they are present.

sudo dnf install cmake gcc make curl -y

Install Rust Programming Language

Once you have completed the required installation of packages in prerequisites, you can now use (curl) to download the Rust installation script by executing the following command:

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

You should see an output like the example below.

Type 1 and hit Enter to continue.



Example:

How to Install Rust on Rocky Linux 9

The installation should take 1 to 5 minutes, depending on your server’s internet speed and hardware.

Next, you must activate your current shell (Rust environment). This is done using the following command to start the rust environment:

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

Verify the version build of Rust installed, which will show you it is also successfully installed. Type the following command and hit enter:

rustc -V

Example output:

rustc 1.64.0 (a55dd71d5 2022-09-19)

Create Rust Sample Project Application

So you have installed Rust and believe it should be working correctly. When installing a programming language on your operating system, the best way to verify is to create a quick test application. You will make the famous (Hello World) output using rust for the guide.



First, you must create a directory that will serve as a (Workspace).

mkdir path/to/rust-projects

Secondly, change the directory to the Workspace and create a sample application with the following command.

cd rust-projects && nano helloworld.rs

Next, enter the following code for the hello world test.

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

Save and close (CTRL+O) and then exit (CTRL+X), then compile the program with the following command:

rustc helloworld.rs

This will create an executable application after it has finished compiling. The application will be in your current directory as the example output below:

If the test application has been adequately compiled, you will see the HelloWorld file next to the original helloworld.rs file.



Example:

How to Install Rust on Rocky Linux 9

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

./helloworld

Example output from the test application as below:

How to Install Rust on Rocky Linux 9

How to Update/Upgrade Rust Programming Language

Updating Rust is relatively easy and is done with a simple command in your terminal.

rustup update

Example output:

How to Install Rust on Rocky Linux 9

How to Remove (Uninstall) Rust Programming Language

If you no longer require Rust on your operating system in the future, run the following command.



rustup self uninstall

Example output:

How to Install Rust on Rocky Linux 9

To successfully remove type (Y) and press the enter key.

Next, you will get the following result: Rust has been successfully removed from your system.

Comments and Conclusion

Overall, Rust is an excellent choice for programming. Its many features make it a great language for safety-critical systems, and its growing community means you have access to lots of resources when you need them. While I have some criticisms of the language (which I’ll go into in future posts), I believe Rust is worth learning and using in your next project.


Not what you were looking for? Try searching for additional tutorials.

Leave a Comment