How to Install Rust on Arch Linux

Rust is a systems programming language focused on speed, memory safety, and parallelism. Rust is syntactically similar to C++ but can guarantee memory safety by using a borrow checker for validating references. Rust is backed by a large and friendly community of developers committed to improving the language. The Mozilla Foundation also supports the Rust team, ensuring that the language remains free and open source.

Some of the primary purposes of Rust are that it is used in various software applications, such as game engines, operating systems, file systems, browser components, and simulation engines for virtual reality. Thanks to its focus on safety and performance, Rust has quickly become a popular choice among developers for many projects. In addition to being fast and safe, Rust also offers excellent support for concurrent programming. It is often said that Rust is the “programming language of the future” due to its unique combination of features. If you’re looking for a language that offers both speed and safety, Rust is an excellent choice.

For users, especially developers wanting to try out Rust Programming language, you will learn how to install Rust on Arch Linux; the tutorial will teach you how to install the latest version with the official bash script.

Update Arch Linux

First, before proceeding with the tutorial, update your system to ensure all packages are up-to-date to avoid any conflicts using the following command.

Before you proceed, run a quick update to ensure all packages are up-to-date to avoid conflicts.



sudo pacman -Syu

Sometimes, you may need a complete database download if you have not upgraded your Arch Linux system for a while; use the following command if the above update command does not work.

sudo pacman -Syyu

Lastly, Arch Linux being a rolling release, on the rare occasion when updating packages with Pacman GPG keys can become invalid or corrupt. If both commands do not work, use the following command.

sudo pacman -S archlinux-keyring

Once done, use one of the two commands above to check and proceed to upgrade your Arch Linux system.

Install Rust – Arch Linux Repository Method

The first and easiest method is to install Rust directly from the Arch Linux repository. Use the following command to achieve this.

sudo pacman -S rust

Given Arch Linux is a rolling release, this is often up-to-date but can be a version behind the current release depending on how much free time the maintainer has to push the new build.

For users wanting the latest stable version at all times, use the following method.



Install Rust – Rust Repository Method

Once you have completed the required installation of packages in prerequisites, you can now use (curl) to download the Rust installation script by executing the following command.

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

If the above command does not work, you likely do not have the cURL package installed. Use the following command to install it.

sudo pacman -S curl

You should see an output like the example below.

Type 1 and hit Enter to continue.

Example:

How to Install Rust on Arch Linux

The installation should take 1 to 5 minutes, depending on your server’s internet speed and hardware.



Example output if successful:

How to Install Rust on Arch Linux

Next, you must activate your current shell (Rust environment). This is done using the following command to start the rust environment:

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

Verify the version build of Rust installed, which will show you it is also successfully installed. Type the following command and hit enter:

rustc -V

Example output:

rustc 1.64.0 (a55dd71d5 2022-09-19)

Create Rust Sample Project Application

So you have installed Rust and believe it should be working correctly. When installing a programming language on your operating system, the best way to verify is to create a quick test application. You will make the famous (Hello World) output using rust for the guide.

First, you must create a directory that will serve as a (Workspace).



mkdir rust-projects

Secondly, change the directory to the Workspace and create a sample application with the following command.

cd rust-projects && nano helloworld.rs

If nano is not installed, use the default text editor you prefer. For new users of Arch Linux wanting to use nano, install it using the following command.

sudo pacman -S nano

Now, re-launch the file you want to create.

nano helloworld.rs

Next, enter the following code for the hello world test.

fn main() {
    println!("Hello World, this is a test provided by LinuxCapable.com");
}

Save and close (CTRL+O) and then exit (CTRL+X), then compile the program with the following command:

rustc helloworld.rs

This will create an executable application after it has finished compiling. The application will be in your current directory, which you can find using the following command.



ls

If the test application has been adequately compiled, you will see the HelloWorld file next to the original helloworld.rs file.

Example:

How to Install Rust on Arch Linux

To run the application you created using Rust, run the program with the execute command:

./helloworld

Example output from the test application as below:

How to Install Rust on Arch Linux

How to Update/Upgrade Rust Programming Language

Updating Rust is relatively easy and is done with a simple command in your terminal.

rustup update

Example output:



How to Install Rust on Arch Linux

How to Remove (Uninstall) Rust Programming Language

If you no longer require Rust on your operating system in the future, run the following command.

rustup self uninstall

Example output:

How to Install Rust on Arch Linux

To successfully remove type (Y) and press the enter key.

Next, you will get the following result: Rust has been successfully removed from your system.

Comments and Conclusion

Overall, I believe Rust is an excellent choice for programming. Its many features make it a great language for safety-critical systems, and its growing community means you can access lots of resources when needed.


Not what you were looking for? Try searching for additional tutorials.

Leave a Comment