CentOSRHEL Based

How To Install Rust on CentOS Stream 9

Install Rust on CentOS Stream 9

In this tutorial, we will show you how to install Rust on CentOS Stream 9. Rust is a modern systems programming language that emphasizes safety, speed, and concurrency. Its tools help you manage your projects, and packages, and build scripts with ease.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Rust programming language on CentOS Stream 9.

Prerequisites

  • A server running one of the following operating systems: CentOS Stream 9.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection.
  • You’ll need administrative privileges or root access on your CentOS Stream 9 system. If you don’t have them, reach out to your system administrator.

Install Rust on CentOS Stream 9

Step 1. Keeping your system up to date is crucial for security and compatibility. Execute the following command to update your system:

sudo dnf clean all
sudo dnf update
sudo dnf groupinstall "Development Tools"

This command will update all the installed packages on your CentOS system.

Step 2. Installing Rust Programming Language on CentOS Stream 9.

Rust installation is facilitated by a script provided by Rust. Use curl to download and execute this script:

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

Follow the on-screen instructions. The default installation options are recommended for most users.

Step 3. Configure the Environment.

To use Rust, you need to add it to your PATH. This step makes the Rust compiler (rustc), Cargo (Rust’s package manager), and other tools available in your terminal:

source $HOME/.cargo/env

To ensure Rust is always in your PATH, add the above command to your .bashrc or .bash_profile:

echo 'source $HOME/.cargo/env' >> ~/.bashrc
source ~/.bashrc

Check if Rust has been installed correctly by querying the version of rustc:

rustc --version

Step 4. Writing Your First Rust Program.

Create a new file named hello_world.rs and open it in your favorite text editor. Add the following Rust code:

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

Compile and run your Rust program using:

rustc hello_world.rs
./hello_world

You should see “Hello, world!” printed on the terminal.

Step 5. Using Cargo, Rust’s Package Manager.

Cargo simplifies Rust project management. To create a new project:

cargo new my_project
cd my_project

Build and run your project with Cargo:

cargo build
cargo run

Congratulations! You have successfully installed Rust. Thanks for using this tutorial to install Rust programming language on CentOS Stream 9. For additional help or useful information, we recommend you check the official Rust website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button