Rust is a powerful and versatile programming language that prioritizes performance, type safety, and concurrency. It enforces memory safety without the need for a garbage collector or reference counting, making it a popular choice among developers. In this guide, we will walk you through the step-by-step process of installing Rust on AlmaLinux 9, ensuring that you have all the necessary tools to start coding in Rust.
Prerequisites
Before we begin the installation process, make sure you have the following prerequisites in place:
- A system with AlmaLinux 9 installed and running.
- A minimum of 2GB of RAM.
- Root access to the system.
To get started, we need to install several development tools. Open the terminal and run the following command to install them:
dnf install curl epel-release cmake gcc make -y
Updating the System
Before installing Rust, it’s essential to ensure that your system is up-to-date. Run the following commands in the terminal:
dnf check-update dnf update -y
Installation of Rust
To install Rust, we will use the rustup command-line tool. Follow these steps to install Rust:
- Open the terminal and run the following command to download the rustup command:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- The installation process will begin, and you will be prompted with installation options. Choose option 1 to proceed with the default installation.
- Once the installation is complete, run the following command to add the Rust toolchain directory to the PATH environment variable:
source "$HOME/.cargo/env"
- Verify the installation by requesting the Rust version:
rustc --version
If everything is installed correctly, you should see the version number displayed in the terminal.
Setting up a Test Program
Now that Rust is installed on your system, let’s create a simple test program to ensure everything is functioning correctly. Follow these steps:
- Create a directory to store your test program:
mkdir ~/rustprojects cd ~/rustprojects mkdir testdir cd testdir
- Use a text editor to create a new file called
test.rs
:
nano test.rs
- In the
test.rs
file, add the following code:
fn main() { println!("Congratulations! You have installed Rust, and your program works."); }
- Save the file and exit the text editor.
Compiling and Running the Test Program
With the test program created, let’s compile and run it to ensure everything is functioning as expected. Follow these steps:
- Compile the code using the
rustc
command:
rustc test.rs
- Run the resulting executable:
./test
If everything is set up correctly, you should see the message “Congratulations! You have installed Rust, and your program works.” displayed in the terminal.
Updating Rust
To keep your Rust installation up-to-date, you can use the rustup
command. Here’s how to update Rust:
- Open the terminal and navigate to the directory where you created your test program:
cd ~/rustprojects/testdir
- Run the following command to update Rust:
rustup update
Conclusion
Congratulations! You have successfully installed Rust on AlmaLinux 9 and verified its functionality by creating and running a test program. Rust’s performance, type safety, and concurrency features make it an excellent choice for developing robust and efficient applications. Now you’re ready to dive into the world of Rust programming and explore the endless possibilities it offers.
Remember to keep your Rust installation up-to-date to benefit from the latest features and improvements. Happy coding!
At Shape.host, we offer reliable and scalable Cloud VPS solutions to empower businesses with efficient and secure hosting services. Whether you’re a beginner or an experienced developer, our cloud hosting services provide the flexibility and performance you need to bring your ideas to life. Visit us at Shape.host to learn more about our services and how we can support your development needs.