Rust is a versatile programming language that prioritizes performance, type safety, and concurrency. It enforces memory safety without relying on garbage collection or reference counting. If you’re looking to install Rust on RockyLinux 9, this comprehensive guide will walk you through the process step by step.
Prerequisites
Before you begin the installation process, make sure you have the following prerequisites:
- A system with RockyLinux 9 installed and running.
- A minimum of 2GB of RAM.
- Root access to the system.
Additionally, you need to have several development tools installed. Use the following command to install them:
dnf install cmake gcc make curl clang -y
Update the System
To ensure a smooth installation, it’s important to update your system before proceeding. Use the following commands to check for updates and update your system:
dnf check-update dnf update -y
Install the EPEL Repository
The next step is to install the EPEL (Extra Packages for Enterprise Linux) repository, which provides additional software packages for RockyLinux. Execute the following command to install the EPEL repository:
dnf install epel-release -y
Install Rust
To install Rust, we’ll use the rustup
command-line tool. Follow the steps below:
- Download the
rustup
command by running the following command:
curl --proto '=https' --tlsv1.2-sSf https://sh.rustup.rs | sh
- After the download completes, you’ll see the Rust installation prompt. Press
1
to proceed with the default installation. - Once the installation is complete, you need to add the Rust toolchain directory to the PATH environment variable. Use the following command to achieve this:
source "$HOME/.cargo/env"
Verify the Installation
To ensure that Rust has been successfully installed, you can check the version by running the following command:
rustc --version
If the installation was successful, you’ll see the version number of the Rust compiler.
Installing a Compiler
Now that Rust is installed, let’s move on to creating, compiling, and running a test program. We’ll start by creating the necessary directories:
mkdir ~/rustprojects cd ~/rustprojects mkdir testdir cd testdir
Next, create a file called test.rs
within the testdir
directory and add the following code:
fnmain(){ println!("Congratulations! You have installed your Rust program, and it works."); }
Save the file and compile the code using the rustc
command:
rustc test.rs
Finally, run the resulting executable by executing the following command:
./test
If everything is set up correctly, you should see the following output:
Congratulations! You have installed your Rust program, and it works.
Updating Rust
To keep your Rust installation up to date, you can use the rustup
command. Run the following command to update Rust:
rustup update
This command will sync with the Rust channel updates and check for any updates to the Rust toolchain. If an update is available, it will be installed.
Conclusion
Congratulations! You have successfully installed Rust on RockyLinux 9 and tested it by running a simple program. Rust’s focus on performance, type safety, and concurrency makes it a powerful language for various programming tasks.
Remember to keep your Rust installation up to date by regularly running the rustup update
command. This ensures that you have access to the latest improvements and bug fixes.
If you’re looking for reliable and scalable cloud hosting solutions, Shape.host offers Linux SSD VPS services that can accommodate your Rust development needs. Their expert team provides efficient and secure hosting options, allowing you to focus on building great software.
Now that you have Rust up and running, it’s time to dive deeper into the language and explore its capabilities. Happy coding!