Home  »  ArticlesGuidesHow ToProgrammingTechnologyTools   »   How to Install Rust on Debian 11 Using Installer Script

How to Install Rust on Debian 11 Using Installer Script

This is the tutorial where you will learn how to install Rust on Debian 11 Linux system. We will be using the terminal and a non-root user with sudo privileges.

Rust is a multi-paradigm, general-purpose programming language designed for performance, efficiency, and safety, especially with regards to concurrency. Like C++ it contains no garbage collector and is also syntactically similar but unlike C++ it is type-safe. See more details here.

Install Rust on Debian 11

Step 1: Update the package list and upgrade any packages.

$ sudo apt update && sudo apt upgrade

Step 2: Install the compiler and other build tools.

$ sudo apt install curl build-essential gcc make

Step 3: Install Rust Programming Language on the Debian system from the installation script.

wget -qO - https://sh.rustup.rs | sudo RUSTUP_HOME=/opt/rust CARGO_HOME=/opt/rust sh -s -- --no-modify-path -y

Step 4: Execute the following commands to add the rust environment variables.

echo 'export RUSTUP_HOME=/opt/rust' | sudo tee -a /etc/profile.d/rust.sh
echo 'export PATH=$PATH:/opt/rust/bin' | sudo tee -a /etc/profile.d/rust.sh

Step 5: Configure the current shell by running the following command.

$ source /etc/profile
$ echo $PATH

Now let’s confirm the installation by running the following command.

$ rustc --version

rustc 1.53.0

Write Your First Rust Program

Let’s write a simple rust program to display text to screen.

$ mkdir ~/projects
$ cd ~/projects
$ mkdir hello_world
$ cd hello_world

Create a new file with the .rs extension.

$ sudo nano hello_world.rs

Add the following function to the file.

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

Compile and run the program.

$ rustc hello_world.rs 
$ ./hello_world

Here’s your output.

Hello, world!

That’s how to install Rust on Debian 11 using the install script. We have prepared a guide where you can install Rust on Ubuntu 20.04 using apt package manager.

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.