How to Install Rust on RockyLinux 9
Rust is a multi-paradigm, general-purpose programming language that emphasizes performance, type safety, and concurrency. It enforces memory safety—ensuring that all references point to valid memory—without requiring the use of a garbage collector or reference counting present in other memory-safe languages.
Prerequisites
-
A system with RockyLinux 9 installed and running.
-
Min 2GB of RAM.
root
access to the system.
Rust requires several development tools. Install them using the following command,
dnf install cmake gcc make curl clang -y
Update the System
Before installing Rust, ensure your system is up-to-date by running,
dnf check-update
dnf update -y
Install the EPEL Repository
Installing the EPEL repository using the below command.
dnf install epel-release -y
Install Rust
Install the Rust using rustup
command line tool,
Run the below command to install curl
and then download the rustup
command,
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Output:
root@vps:~# curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
info: downloading installer
Welcome to Rust!
This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.
Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:
/root/.rustup
This can be modified with the RUSTUP_HOME environment variable.
The Cargo home directory is located at:
/root/.cargo
This can be modified with the CARGO_HOME environment variable.
The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:
/root/.cargo/bin
This path will then be added to your PATH environment variable by
modifying the profile files located at:
/root/.profile
/root/.bashrc
You can uninstall at any time with rustup self uninstall and
these changes will be reverted.
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
>
info: profile set to 'default'
info: default host triple is x86_64-unknown-linux-gnu
Run the below command to add the Rust toolchain directory to the PATH environment variable,
source "$HOME/.cargo/env"
Verify the Installation
Verify the Rust installation by requesting the version,
rustc --version
Output:
root@vps:~# rustc --version
rustc 1.71.1 (eb26296b5 2023-08-03)
root@vps:~#
Installing a Compiler
Creating, Compiling, and Running a Test Program, Start by creating some directories to store the test script,
mkdir ~/rustprojects
cd ~/rustprojects
mkdir testdir
cd testdir
Create a file in testdir to store your Rust code,
nano test.rs
You need to use the .rs extension for all your Rust programs.
Add the following code into test.rs and save the file,
fn main() {
println!("Congratulations! You have installed your Rust program and it works.");
}
Compile the code using the rustc command,
rustc test.rs
Run the resulting executable,
./test
Output:
root@vps:~/rustprojects/testdir# ./test
Congratulations! You have installed your Rust program and it works.
root@vps:~/rustprojects/testdir#
Use the below command to update the rustup,
rustup update
Output:
root@vps:~/rustprojects/testdir# rustup update
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: checking for self-update
stable-x86_64-unknown-linux-gnu unchanged - rustc 1.71.1 (eb26296b5 2023-08-03)
info: cleaning up downloads & tmp directories
root@vps:~/rustprojects/testdir#
Done, you’ve installed and tested out Rust on RockyLinux 9.
CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME
for 10% off!
1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month
Available Locations: LAX | MIA | ATL | FRA | AMS