Rust programming language is a multi-paradigm system programming language by Mozilla that focuses on having the best features of the C++ and Python languages with a focus on security.
Rust was designed to be a safe, concurrent, and practical language. It aims to ensure memory safety while still maintaining performance, without needing any garbage collector or runtime, thus making it possible to use Rust as an embedded system’s primary programming language. As such, Rust is used in many single-board computers, including Raspberry Pi and BeagleBone Black.
The language has found use in web development, being used in the Firefox web browser’s rendering engine and the Servo parallel layout engine. Rust is also being used to develop WebAssembly, a new standard for compiling code to run in web browsers. This makes it possible to write high-performance code that can run in any web browser without the need for a plugin.
In conclusion, Rust is a powerful, safe and fast programming language that is becoming increasingly popular in many different industries. It provides many features that are not found in other languages, making it a great choice for development projects of all sizes.
In this tutorial, we will show you how to install and configure the Rust Programming Language on AlmaLinux 8. We will also create a Hello World example to show you how to get started with Rust.
Prerequisites
In order to install the Rust Programming Language on AlmaLinux 8, you must have:
- Root access on your server or virtual machine.
- A server with a minimum of 2 GB RAM and 20 GB of hard disk to smooth out the installation process.
Updating the System
Before installing any software on your system, it is always a good idea to update the packages and repositories. You can do this by running the following command.
sudo dnf check-update && sudo dnf update -y
Once the command finishes, run the command below to install required dependencies.
sudo dnf install curl epel-release cmake gcc make -y
Installing Rust on AlmaLinux 8
Now that the system has been updated, we are ready to install the Rust Programming Language.
We will use curl to download a script that will install the latest version of rust in our system using the DNF package manager. Thanks to the developer team, we can simply install Rust system-wide by typing the commands below.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
This command will download the rustup.rs script from the Rust project’s website and execute it using the sh shell.
Sample output:
Once the installation is finished, run the command below to update the PATH environment variable.
source ~/.profile
Next. run the command below to update the CARGO environment variable.
source ~/.cargo/env
Finally, open a new terminal window and type the rustc command with the -V flag to verify that Rust has been installed correctly. Rustc is the compiler for the Rust Programming Language.
rustc -V
The output should be something like this. This output shows that you have Rust installed in your system.
Now that we’ve successfully installed the Rust Programming Language, let’s take a look at how to create a Hello World example.
Testing the Installation
Now that Rust has been installed, let’s create a basic “Hello World” program to test the installation.
First, let’s create a new directory to put our new Rust project in our home directory.
cd && mkdir hello_world
Next, switch to this directory using the cd command.
cd hello_world
Then, create a file called hello_world.rs with nano or your favorite text editor.
sudo nano hello_world.rs
After the file has been opened, copy and paste the following code.
fn main() { println!("Hello World, this is an example provided by vitux.com"); }
Where:
- fn main() {}: This is the main() function, which is where our program will run.
- println!(“Hello World, this is an example provided by vitux.com”);: This line prints “Hello World” to the console.
- }: The closing bracket for the main() function.
If you are running this within an SSH session, it is important to close nano by pressing CTRL+X, Y, and Enter.
Now, compile the program using the rustc command and pass in the file name as the only argument.
rustc hello_world.rs
Once the program has compiled successfully, you will notice that there are now two new files in our directory; one is called “hello_world.rs” and the other executable file named “hello_world”. This executable file can be run on its own and on any system that has Rust installed.
To run the program, type the following command in your terminal.
./hello_world
The program will print exactly what you expect to see “Hello World, this is an example provided by vitux.com”. Congratulations! You have successfully installed and tested the Rust Programming Language on your AlmaLinux system.
There are many resources online where you can go to learn more about this programming language. You can refer to its official website where contains all of the information you need to get started, including documentation, guides, and a community forum. There are also many books about Rust that can be found on Amazon or other online bookstores. Lastly, there are many video tutorials available on YouTube that can walk you through different aspects of the language.
Conclusion
In this article, we have shown you how to install Rust on AlmaLinux 8. We have also created a basic “Hello World” program to test the installation. Leave a comment below and let us know if you have any questions or need help.