Rust is a free and open-source server-side programming language developed by Mozilla. It mainly focused on speed, memory safety, and replacing low-level coding languages like C/C++. It is used to create a wide range of applications including game engines, operating systems, file systems, browser components, and more. It can run on embedded devices and easily integrate with other languages.
In this post, we will show you how to install the Rust programming language on Rocky Linux 8.
Step 1 – Install Required Dependencies
First, you will need to install some required dependencies on your server. You can install all of them by running the following commands:
dnf install epel-release -y dnf install cmake gcc make curl clang -y
Once all the dependencies are installed, you can proceed to the next step.
Step 2 – Install Rust on Rocky Linux 8
Now, run the following command to download and run the Rust installation script:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
You will be asked to select the installation option as shown below:
home directory, located at: /root/.rustup This can be modified with the RUSTUP_HOME environment variable. The Cargo home directory 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/.bash_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 >1
Type 1 and hit Enter to start the installation. Once the installation is complete, you will get the following output:
stable-x86_64-unknown-linux-gnu installed - rustc 1.56.0 (09c42c458 2021-10-18) Rust is installed now. Great! To get started you may need to restart your current shell. This would reload your PATH environment variable to include Cargo's bin directory ($HOME/.cargo/bin). To configure your current shell, run: source $HOME/.cargo/env
Now, activate the Rust system path variable using the following command:
source ~/.profile source ~/.cargo/env
Now, verify the Rust version with the following command:
rustc -V
You should see the Rust version in the following output:
rustc 1.56.0 (09c42c458 2021-10-18)
Step 3 – Create a Rust Application
At this point, Rust is installed. Now, let’s create a sample application to test Rust.
First, create a directory named project with the following command:
mkdir project
Next, change the directory to the project and create a sample Rust application with the following command:
cd project nano helloworld.rs
Add the following code:
fn main() { println!("This is my first project created using rust!"); }
Save and close the file, then compile the program using the following command:
rustc helloworld.rs
This command will create an executable file in your current directory.
Now, run the program with the following command:
./helloworld
You should see the following output:
This is my first project created using rust!
Step 4 – Update Rust to the Latest Version
It is always a good idea to use the latest version of Rust. You can update it with the following command:
rustup update
Step 5 – How to Uninstall Rust
If you want to remove Rust from your system, run the following command:
rustup self uninstall
After the successful uninstall, you will get the following output:
Thanks for hacking in Rust! This will uninstall all Rust toolchains and data, and remove $HOME/.cargo/bin from your PATH environment variable. Continue? (y/N) y info: removing rustup home info: removing cargo home info: removing rustup binaries info: rustup is uninstalled
Conclusion
In the above post, we explained how to install the Rust programming language on your Rocky Linux 8. We also create a sample application using Rust. You can now start creating your application using the Rust language. Try using Rust on your VPS from Atlantic.Net!