Install Rust on Debian 11

This guide will take you through how to install Rust on Debian 11. Rust is a multi-paradigm, general-purpose programming language that emphasizes performance, type safety, and concurrency. It ensures memory safety, which requires that all references point to legitimate memory, without requiring a garbage collector or reference counting, which are needed in other memory-safe languages.

How to Install Rust on Debian 11

  • Update your packages.
sudo apt update
  • Then install dependencies such as curl and build-essentials.
sudo apt install curl build-essential gcc make

Sample output

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu dpkg-dev
  fakeroot g++ g++-10 gcc-10 libalgorithm-diff-perl
  libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan6
  libbinutils libc-dev-bin libc-devtools libc6-dev libcc1-0
  libcrypt-dev libctf-nobfd0 libctf0 libcurl4 libdpkg-perl
  libfakeroot libgcc-10-dev libitm1 liblsan0 libnsl-dev
  libstdc++-10-dev libtirpc-common libtirpc-dev libtirpc3 libtsan0
  libubsan1 linux-libc-dev manpages-dev patch
Suggested packages:
  binutils-doc debian-keyring g++-multilib g++-10-multilib gcc-10-doc
  gcc-multilib autoconf automake libtool flex bison gdb gcc-doc
  gcc-10-multilib gcc-10-locales glibc-doc git bzr libstdc++-10-doc
  make-doc ed diffutils-doc
The following NEW packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu build-essential
  curl dpkg-dev fakeroot g++ g++-10 gcc gcc-10 libalgorithm-diff-perl
  libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan6
  libbinutils libc-dev-bin libc-devtools libc6-dev libcc1-0
  libcrypt-dev libctf-nobfd0 libctf0 libfakeroot libgcc-10-dev
  libitm1 liblsan0 libnsl-dev libstdc++-10-dev libtirpc-dev libtsan0
  libubsan1 linux-libc-dev make manpages-dev patch
The following packages will be upgraded:
  libcurl4 libdpkg-perl libtirpc-common libtirpc3
4 upgraded, 36 newly installed, 0 to remove and 57 not upgraded.
Need to get 51.4 MB/53.4 MB of archives.
After this operation, 197 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
  • Install Rust using the following command.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Sample output

Current installation options:


   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

info: profile set to 'default'
info: default host triple is x86_64-unknown-linux-gnu
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
703.5 KiB / 703.5 KiB (100 %) 196.6 KiB/s in  3s ETA:  0s
info: latest update on 2022-08-11, rust version 1.63.0 (4b91a6ea7 2022-08-08)
info: downloading component 'cargo'
  6.6 MiB /   6.6 MiB (100 %) 770.9 KiB/s in  8s ETA:  0s
info: downloading component 'clippy'
  2.8 MiB /   2.8 MiB (100 %) 698.3 KiB/s in  4s ETA:  0s
info: downloading component 'rust-docs'
 18.3 MiB /  18.3 MiB (100 %) 907.8 KiB/s in 30s ETA:  0s
info: downloading component 'rust-std'
 26.1 MiB /  26.1 MiB (100 %) 844.8 KiB/s in 34s ETA:  0s
info: downloading component 'rustc'
 54.3 MiB /  54.3 MiB (100 %) 770.5 KiB/s in  1m 20s ETA:  0s
info: downloading component 'rustfmt'
  4.1 MiB /   4.1 MiB (100 %) 893.3 KiB/s in  5s ETA:  0s
info: installing component 'cargo'
  6.6 MiB /   6.6 MiB (100 %)   5.4 MiB/s in  1s ETA:  0s
info: installing component 'clippy'
info: installing component 'rust-docs'
 18.3 MiB /  18.3 MiB (100 %)   1.5 MiB/s in 17s ETA:  0s
info: installing component 'rust-std'
 26.1 MiB /  26.1 MiB (100 %)   4.9 MiB/s in  5s ETA:  0s
info: installing component 'rustc'
 54.3 MiB /  54.3 MiB (100 %)   9.7 MiB/s in  5s ETA:  0s
info: installing component 'rustfmt'
info: default toolchain set to 'stable-x86_64-unknown-linux-gnu'

  stable-x86_64-unknown-linux-gnu installed - rustc 1.63.0 (4b91a6ea7 2022-08-08)


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"  
  • Activate the Rust environment after the installation using the following commands.
source ~/.profile
source ~/.cargo/env
  • Add rust compiler to your system.
sudo apt install rustc
  • Confirm the version of Rust installed.
rustc -V

Sample Rust application

  • Let’s create a directory for the sample rust application.
sudo mkdir ~/rust-demoproject
  • Next, go to the created directory.
cd ~/rust-demoproject
  • Then create a sample app.
sudo nano helloearth.rs
  • Copy the code below and paste it to the file created above. Save(ctrl+s) and close(ctrl+x) the file.
fn main() {
println!("Hello from itnixpro.com");
}
  • Compile the app created.
rustc helloearth.rs
  • Run the compiled application using the following command.
./helloearth

Update Rust on Debian 11

  • Update Rust programming language using the command below.
rustup update

Uninstall Rust on Debian 11

  • Remove Rust from your system using the following command.
rustup self uninstall

Sample output

Thanks for hacking in Rust!

This will uninstall all Rust toolchains and data, and remove
$HOME/.cargo/bin from your PATH environment variable.

Continue? (y/N) y

info: removing rustup home
info: removing cargo home
info: removing rustup binaries
info: rustup is uninstalled
  • You have reached the end of our article, we have gone through how to install Rust on Debian 11.

Read more about Rust

Other Tutorials

Install Node.js on Ubuntu 22.04

Install Java 18 in Ubuntu 22.04

Install PHP 8 on Rocky Linux 9

System administrator | Software Developer | DevOps

Leave a Comment