How to Install the Rust Compiler on Linux

In this quick tutorial, we will show you how to install the Rust compiler on a Linux-based operating system.

Linux Install Rust Compiler

Rust is a programming language that has become well-regarded thanks to its focus on performance, type safety, and concurrency.

To program with Rust on Linux you will need the Rust Compiler. Put simply, the compiler is a special program that takes your code and compiles it into something you can actually run.

While most operating systems package repositories offer a way to install this compiler, it can often be significantly outdated. These versions become outdated because most operating systems freeze major changes when they push a new release.

Luckily, the Rust Foundation has developed their own tool that makes getting the latest version of the Rust compiler an incredibly easy process. That tool is called Rustup.

The steps we cover here should work for most Linux systems without major changes. All you need for this to work is curl. These steps should even work on a Raspberry Pi.

Installing the Rust Compiler on Linux from the Terminal

Over the next few steps, we will walk you through the very simple process of installing the latest version of the Rust Compiler on Linux.

If you are running these tutorials from a desktop system, you can often bring up the terminal by pressing CTRL + ALT + T.

Before You Get Started

1. If you have installed Rust through any other method previously, you will want to uninstall it before continuing.

To install the latest version of Rust onto your Linux system, we will use a tool called Rustup. This tool installs the Rust compiler to the local user’s home directory.

Because of how it works, an existing installation of Rust through a package manager will cause conflicts and should be removed.

Using Rustup to Install the Rust Compiler on Linux

2. Once you are ready to proceed, we can launch the Rustup install script on your machine using the following command. As mentioned earlier, Rustup is the tool that makes installing the Rust Compiler and its tool chain a relatively straightforward process.

With this command, we use curl to grab the Rustup installer script and pipe it directly into the shell. It is recommended to verify the contents of this script before running it directly like we do with the command below.

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

3. Once you run this script, you will see a list of places where Rustup intends to install the Rust Compiler and its package manager Cargo on your Linux system.

This script will install everything to the current user’s home directory by default. This is the intended way of setting up the Rust toolchain and is what we will be doing. Please note that you will need to re-run this tool for every user who intends to use the Rust Compiler.

To proceed with these default settings, all you need to do is press ENTER on your keyboard. Alternatively, you can also type in “1” and press ENTER.

info: downloading installer

Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

  /home/pimyubu/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  /home/pimyubu/.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:

  /home/pimyubu/.cargo/bin

This path will then be added to your PATH environment variable by
modifying the profile files located at:

  /home/pimyubu/.profile
  /home/pimyubu/.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 standard installation (default - just press enter)
2) Customize installation
3) Cancel installation

4. Once the installation process has completed, you will want to use the following command to load in the updated environment variables.

Without this, your Linux system will be unaware that it can now access Rust and its package manager Cargo until you restart your machine or the current shell session.

source "$HOME/.cargo/env"

Verifying the Rust Compiler is Installed

5. Verifying and checking the version of the Rust Compiler that you have installed on Linux is as simple as running the command below.

With this command, we simply get the Rust Compiler to output its version number.

rustc --version

The response below shows that we are running version 1.81.0 of the Rust Compiler, which was released on September 4th, 2024.

rustc 1.81.0 (eeb90cda1 2024-09-04)

Updating to the Latest Version of the Rust Compiler on Linux

As the Rust Foundation releases updates to their compiler fairly often, you should know how to update to the latest version. While the language doesn’t change drastically these days, improvements are often made to the toolchain. These can improve compiling performance or fix bugs that may occur under particular scenarios.

Luckily, thanks to us using Rustup to install the Rust Compiler on Linux, the whole update process is incredibly straightforward.

1. To update to the latest stable release of the Rust Compiler on Linux, you only need to run the following command.

Rustup will check the Rust servers for a new release and update if a new one is available.

rustup update

2. Verifying that you have the latest release of Rust is as simple as getting it to output its version number.

rustc --version

Conclusion

Hopefully, you will have successfully installed the Rust Compiler on your Linux operating system.

Using this compiler on Linux enables you to easily compile any program written in Rust. Additionally, this compiler also comes alongside the Cargo package manager for Rust.

Please feel free to comment below if you have had any issues with getting started with Rust on Linux.

If you found this quick Linux guide useful, we recommend you take some time to explore our many other Linux guides.

Leave a Reply

Your email address will not be published. Required fields are marked *