How To Install Rust Lang on Linux

By Chandrashekhar Fakirpure

Updated on Feb 02, 2024

In this tutorial, we will show the steps to install Rust Lang on Linux. These steps can be followed on Ubuntu, AlmaLinux, Rocky Linux.

Rust is blazingly fast and memory-efficient: with no runtime or garbage collector, it can power performance-critical services, run on embedded devices, and easily integrate with other languages.

Rust or rust-lang is a general-purpose programming language for system-level development projects. Rust is known for its speed, memory efficiency, seamless integration with other languages, and type safety.

We have covered installation and configuration of the Rust Lang on Linux.

Prerequisites

  • A Linux OS installed dedicated server or KVM VPS.
  • A root user access or normal user with sudo privileges.

Step 1 - Install Dependency

Run the following command in your terminal then follow the on-screen instructions.

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

Here, you can proceed with default installation or customize it. For default installation, type 1 and enter.

       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

Once the installation gets done, it will ask you to restart your current shell.

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"

Step 3 - Verify the Installation

Execute rustc with the -V argument to check the version of the Rust and also to confirm the installation.

rustc -V

Output

rustc 1.67.1 (d5a82bbd2 2023-02-07)

Step 4 - Write Hello World! Program

This is the source code of the traditional Hello World! program.

fn main() {
    println!("Hello, world!");
}

A binary can be generated using the Rust compiler: rustc.

rustc hello.rs

rustc will produce a hello binary that can be executed.

./hello

Output:

Hello World!

We have seen, how to install Rust Lang on Linux. Here is the Rust Lang official Documentation.