How to Install Rust on Debian 11

Install Rust on Debian 11

In this article, we will have explained the necessary steps to install Rust on Debian 11. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Rust is a programming language compiled, general-purpose, and multiparadigm that is being developed by Mozilla and supported by LLVM. Rust has been adopted by hundreds of big companies in production environments. From applications like Dropbox, Firefox, and Cloudflare.

Install Rust on Debian 11

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo apt update
sudo apt upgrade
sudo apt install curl build-essential gcc make

Step 2. Install Rust Programming Language on Debian system.

Installing Rust on your Debian system is straightforward, All you need to do is open a terminal and run the following command:

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

Next, execute the following command to add the environment variable:

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

Finally, configure the current shell by running the following command:

source /etc/profile
echo $RUSTUP_HOME
echo $PATH

Now only we must proceed to verify that Rust was installed correctly in our system, we do this by typing the following command on the terminal:

rustc --version

Step 3. Testing the Rust programming language.

For this example, you will be creating hello-world Rust using a non-root user.

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

Create a new file with the .rs extension. Example:

sudo nano hello_world.rs
fn main() {
    println!("Hello, world!");
}

Then, compile and run the program:

rustc hello_world.rs 
./hello_world

Output:

Hello, world!

That’s all you need to do to install Rust on Debian (Bullseye). I hope you find this quick tip helpful. For further reading Rust Programming Language on Debian’s system, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.