How to Install Rust Programming Language on Debian 11

Rust has been adopted by hundreds of big companies in production environments. From applications like Dropbox, Firefox, and Cloudflare, to embedded devices and scalable web services, Rust can be used on all those types of applications and deployments.

rustup is a tool part of the Rust project that allows you to install Rust programming language to your system. Using rustup allows developers easily to manage and maintain Rust. Also, it enables you to switch between stable, beta, and nightly compilers and makes the cross-compiling process easier.

In this guide, you will learn how to install Rust programming language on the Debian 11 Bullseye. We will be using the rustup toolchain for installing and managing Rust on the Debian system.


To complete this guide, ensure you have got the following requirements:

  • Operating System: Debian 11 Bullseye
  • Root privileges

Now let's start the installation.

Installing Packages Dependencies

First, you will be installing packages dependencies such as build-essentials, GCC, make, etc to your Debian system.

1. Run the 'sudo su' command below to get root privileges, then update and refresh your repository.

sudo su
sudo apt update

2. Now install packages dependencies using the following command.

sudo apt install curl build-essential gcc make -y

The installation will take some time, depending on your internet connection.

Installing Rust with rustup

rustup is an official project backed by Rust that allows you to install Rust most easily. rustup provides an installer for Unix-like operating systems and Windows.

In this step, you will be installing Rust programming language using the rustup on the Debian system.

1. Execute the following command to download the rustup installer and install Rust system-wide.

wget -qO - | sudo RUSTUP_HOME=/opt/rust CARGO_HOME=/opt/rust sh -s -- --no-modify-path -y

This command will download the rustup toolchain to the custom installation directory '/opt/rust'. Also, define the environment variable for 'RUSTUP_HOME' and 'CARGO_HOME' to the directory '/opt/rust'.

The installation will take some time, depending on your system spec and internet connection.

If the Rust installation completes, you will see the output message 'Rust is installed now. Great!'.

Install Rust with rustup

2. After rustup installation completes, execute the following command to add the environment variable '$RUSTUP_HOME=/opt/rust' and the binary path of rustup toolchain '/opt/rust/bin' to the '$PATH' environment variable. This will make environment variables permanent and automatically load at every login.

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

Now execute the following command to reload your current shell profile. This will apply a new shell configuration, including new environment variables.

source /etc/profile

Verify the '$RUSTUP_HOME' and '$PATH' environment variables using the following command.

echo $PATH

If your configuration is correct, you will see a similar output as below.

Setup RUSTUP_HOME and PATH binary environment variable

The '$RUSTUP_HOME' directory is '/opt/rust' and the rustup toolchain binary path is '/opt/rust/bin' directory.

3. To verify Rust installation, execute the following command using the following command.

rustc --version

You will see a similar output as below.

rustc 1.56.1 (59eed8a2a 2021-11-01)

Rust system-wide installation allows you to run Rust with different users, including the non-root user.

Log in as your user and check the Rust version as below.

su - username
rustc --version

You will see a similar output as below.

Verify Rustup

4. By default, rustup provides command completions for a different types of shells, including bash.

Execute the following command to generate the rustup command completion for the bash.

rustup completions bash > /usr/share/bash-completion/completions/rustup

Now reload the bash_completion profile to apply a new configuration.

source /etc/profile.d/

Now type the 'rustup' command and press 'TAB' to get the list of rustup command completions.

rustup TAB

Below is the similar output you will get.

Enable autocomplete rustup

Now you've concluded the Rust installation of the Debian system using the rustup.

Setting up Rust Project

The main advantage of installing Rust system-wide is all users can use it without any additional package installation and configuration.

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

Log in as your user using the following command.

su - username

1. Create a new directory '~/project' and change your working directory into it.

mkdir -p ~/project; cd ~/project

2. Create a new Rust script '' using your favorite editor.


Copy and paste the following Rust code for a simple hello-world message.

fn main() {
    println!("Hello World, welcome to Rust.");

Save the file.

3. Compile the script using the 'rustc' command below.


The output of the will be an executable file 'hello-world'.

4. Execute the binary executable file 'hello-world' as below.


And you will see the 'hello-world' message below.

Rust Hello World

Managing Rust with rustup

rustup has its own configuration file 'settings.toml'. This configuration can be found under the '$RUSTUP_HOME' directory.

1. Setup default Rust toolchain using the rustup command below.

rustup default nightly

2. Setup default Rust profile. You can use minimal, default, or complete.

rustup set profile minimal

3. Compiling Rust code with a specific Rust version

rustup run nightly rustc

4. Show the default toolchain that will be used in the current project directory.

rustup show

5. Show available targets for the current active toolchain. Targets are crossplatform.

rustup target list

6. Remove/uninstall specific toolchains from the current rustup environment.

rustup toolchain uninstall nightly

7. Show help message from rustup sub-command.

rustup toolchain help

Change the 'toolchain' with another sub-command.

8. Show the man page for a specific toolchain.

rustup man cargo

Now you've learned the basic rustup command for managing the Rust environment.

Uninstall Rust and rustup

In case you want to remove the Rust and rustup completely, you can just remove the installation directory '/opt/rust'.

1. Uninstall Rust and rustup completely using the following command.

sudo rm -rf /opt/rust
sudo rm -rf /etc/profile.d/

2. Remove some additional temp directory and unused configuration files.

rm -rf ~/.cargo
rm -f /etc/profile.d/
rm -f /usr/share/bash-completion/completions/rustup


Congratulation! You've successfully installed Rust programming language on the Debian 11 system using rustup. Also, you've learned the basic usage of the rustup command for managing your Rust environment.

Share this page:

Suggested articles

5 Comment(s)

Add comment


By: Taleman

Why not

apt install rustc

By: Roelof Berkepeis

thank you!  this procedure helped me to setup Rust and Rustup on my Devuan Chimaera 4.0 (a Debian 11 derivative) .. but i have some remarks :after seeing 'Rust is installed now. Great!' the text in terminal shows :To configure your current shell, run:source /opt/rust/envi did NOT do this, i just followed your procedure and all seems to have gone OK.later, i also did this command, which you mention :rustup completions bash > /usr/share/bash-completion/completions/rustupbut it gave the error "Permission denied" .. so, i needed to give write permissions to the folder /usr/share/bash-completion/completions/ !?another issue, which i don't understand, is this : when NOT being sudo, the command 'rustc --version' gives nothing : it says rustc is not installed !? Indeed, according to Synaptic, 'rustc' is NOT installed .. Synaptic also shows 'cargo' is NOT installed !? But when i do "su - [username]" and then 'rustc --version', it says that it IS installed, and also cargo .. can you explain ?

By: Tom Dial


apt install rustc will work, but only install cargo, libstd-rust-1.63, libstd-rust-dev, and rustc (on bookworm - earlier versions may be installed on bullseye). The current applicable versions are later, and this will lead to failures installing components using rustup in its normal way. Most of the items are likely in the Debian repositories, and could be installed using apt, but they will, similarly, not necessarily be the most up to date.

The above procedure will install under /opt and not interfere either with Debian operation or updating.

By: Tom Dial

@Roelof Berkepeis:

The description above is not always clear about which account - root or ordinary user - is to be used. Any of the commands that update system files under /usr or /etc need to be run as root, whether logged in as root or using sudo. These include the modifications to /usr/share/bash-completion/ and /etc profile.d/. For security reasons, it is a bad idea to allow anyone but root write permissions in such directories.

Ordinarily, when files that set environment variables are changed it is necessary to either set the variables explicitly or to logout and login again. Using su - to change user id has the same effect.

This install procedure does not affect the databases used by apt, aptitude, apt-get and synaptic; none of them will show that Rust is installed. However, if the procedure is completed correctly, Rust and its core components will be installed and usable from any login account on the system.

By: Tom Dial

I'm entirely new to Rust, but not to Linux.

The instructions here do not mention making CARGO_HOME either global or permanent (per login). Some rustup executions appear to require it:

[email protected]:~# echo [email protected]:~# rustup updateinfo: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'info: syncing channel updates for 'nightly-x86_64-unknown-linux-gnu'error: rustup is not installed at '/root/.cargo'


[email protected]:~# export CARGO_HOME=/opt/[email protected]:~# rustup updateinfo: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'info: syncing channel updates for 'nightly-x86_64-unknown-linux-gnu'info: checking for self-updates   stable-x86_64-unknown-linux-gnu unchanged - rustc 1.67.1 (d5a82bbd2 2023-02-07)  nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.69.0-nightly (31f858d9a 2023-02-28)info: cleaning up downloads & tmp directories

Is this an oversight or done for a reason? Either way, it seems worth mentioning in the section on managing Rust.