Rust is a free and open-source, multi-paradigm, general-purpose programming language developed by Mozilla. It is a server-side programming language designed for performance and safety, especially safe concurrency and memory management. It has direct access to hardware and memory, so it is an ideal language for embedded and bare-metal development. It is used to create a wide range of applications including game engines, operating systems, file systems, browser components, and more.

In this post, we will show you how to install Rust programming language on Oracle 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 update -y
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 Oracle Linux 8

Rust provides an installation script to make the installation process easier.
You can 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.61.0 (fe5b13d68 2022-05-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

After the installation, activate the Rust system path variable using the following command:

source ~/.profile
source ~/.cargo/env

Next, verify the Rust version with the following command:

rustc -V

You should see the Rust version in the following output:

rustc 1.61.0 (fe5b13d68 2022-05-18)

Step 3 – Create Your First Rust Application

At this point, Rust is installed. Now, let’s create a sample application to test the 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!("Welcome to 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:

Welcome to Rust!

Step 4 – How to Update Rust Version

It is always a good idea to use the latest version of Rust. You can update it using the rustup command:

rustup update

Step 5 – How to Uninstall Rust

If you want to remove the 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 this post, you learned how to install Rust programming language on Oracle Linux 8. You also learned how to create a sample application using Rust. You can now install Rust in your development environment and start creating your application using the Rust language. Try it on VPS hosting from Atlantic.Net!