How to install Rust on Rocky Linux

Endrit Qerreti

Endrit Qerreti

In this tutorial, you will learn how to install Rust on Rocky Linux.

By installing Rust on Rocky Linux, it allows you to run and code using Rust programming language.

In this tutorial, we'll be installing Rust on Rocky Linux, via rustup.

Step 1 - Update Rocky Linux System

Before installing Rust on Rocky Linux, ensure that your system is not running outdated packages. If you haven't updated your Rocky Linux machine recently, you can easily do so, by running the command below.

sudo dnf update -y

Step 2 - Install Rust on Rocky Linux

Once you have updated your Rocky Linux system, you can now proceed to install Rust.

Installing Rust on Rocky Linux is quite easily, and it can be done by using the official Rust installer, called Rustup.

So, to install Rust, firs you need to download Rustup, by using curl. To do so, simply execute the following.

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

Next, you need to press 1 to proceed installing Rust.

And Rust's installation process will start.

All you have to do now is wait for the installation process to finish. Once Rust is installed, you will see the following output.

Step 3 - Add RUST to PATH on Rocky Linux

Now that Rust is installed on your Rocky Linux system, in order to be able to use Rust on your terminal, add Rust on your PATH environment variable.

To do so, execute the command below.

source "$HOME/.cargo/env"

Step 4 - Verify Rust installation on Rocky Linux

After adding Rust on your PATH environment variable, now you need to verify that Rust was installed correctly on your Rocky Linux system.

One way of checking if Rust was installed correctly, and that you can use Rust on your terminal, simply check Rust version, by executing the command below.

rustc --version

As you can see, we are running Rust version 1.76.0 on Rocky Linux. This means that Rust is installed and added to PATH successfully.

Step 5 - Create a simple Rust app

Now that Rust is installed, and added on your path environment variable on your Rocky Linux machine, you should be able now to use Rust and write a Rust app.

1) First create the empty file using nano text editor.

sudo nano hello_world.rs

2) Next, copy the content below and paste it to the file that you created.

fn main() {
    // Statements here are executed when the compiled binary is called.

    // Print text to the console.
    println!("Hello World!");
}

3) Save changes, by pressing CTRL + X , then press Y and then press Enter.

4) Compile Rust app

Once you have created the Rust app, you need to compile it using the rust compiler in order to be able to run it.

To do so, simply run the command below.

rustc hello_world.rs

5) Run Rust app

Once the binary for the Rust app that we created is compiled, we can now launch it.

./hello_world

Uninstall Rust on Rocky Linux

If you no longer need Rust installed on your Rocky Linux system, you can uninstall Rust easily by using rustup.

To do so, simply run the command below.

rustup self uninstall -y

💡
Note: Uninstalling Rust from your Rocky Linux machine, will also remove Rust from the environment variable.

Conclusion

In this tutorial, you learned how to install and uninstall Rust on Rocky Linux, by using the official Rust installer rustup.