Install Rust on Ubuntu 22.04

This article will take you through how to install Rust on Ubuntu 22.04. Rust is a multi-paradigm, general-purpose programming language that emphasizes performance, type safety, and concurrency. It guarantees memory safety, which means that all references must point to valid memory, without using a garbage collector or reference counting, which are necessary for other memory-safe languages.

How to Install Rust on Ubuntu 22.04

  • Update your system using the command below.
sudo apt update
  • Then install curl and build-essentials using the following command.
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++-11 gcc-11 libalgorithm-diff-perl
  libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan6
  libatomic1 libbinutils libc-dev-bin libc-devtools libc6-dev
  libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libdpkg-perl
  libfakeroot libfile-fcntllock-perl libgcc-11-dev libitm1
  liblsan0 libnsl-dev libquadmath0 libstdc++-11-dev libtirpc-dev
  libtsan0 libubsan1 linux-libc-dev lto-disabled-list
  manpages-dev rpcsvc-proto
Suggested packages:
  binutils-doc debian-keyring g++-multilib g++-11-multilib
  gcc-11-doc gcc-multilib autoconf automake libtool flex bison
  gcc-doc gcc-11-multilib gcc-11-locales glibc-doc git bzr
  libstdc++-11-doc make-doc
The following NEW packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu
  build-essential curl dpkg-dev fakeroot g++ g++-11 gcc gcc-11
  libalgorithm-diff-perl libalgorithm-diff-xs-perl
  libalgorithm-merge-perl libasan6 libatomic1 libbinutils
  libc-dev-bin libc-devtools libc6-dev libcc1-0 libcrypt-dev
  libctf-nobfd0 libctf0 libdpkg-perl libfakeroot
  libfile-fcntllock-perl libgcc-11-dev libitm1 liblsan0
  libnsl-dev libquadmath0 libstdc++-11-dev libtirpc-dev libtsan0
  libubsan1 linux-libc-dev lto-disabled-list make manpages-dev
  rpcsvc-proto
0 upgraded, 41 newly installed, 0 to remove and 3 not upgraded.
Need to get 54.3 MB of archives.
After this operation, 186 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
  • Next, install Rust on Ubuntu 22.04 LTS.
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 %) 517.4 KiB/s in  1s 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 %) 691.2 KiB/s in 11s ETA:  0s
info: downloading component 'clippy'
  2.8 MiB /   2.8 MiB (100 %) 707.8 KiB/s in  4s ETA:  0s
info: downloading component 'rust-docs'
 18.3 MiB /  18.3 MiB (100 %) 691.2 KiB/s in 27s ETA:  0s
info: downloading component 'rust-std'
 26.1 MiB /  26.1 MiB (100 %) 355.2 KiB/s in 47s ETA:  0s
info: downloading component 'rustc'
 54.3 MiB /  54.3 MiB (100 %) 688.0 KiB/s in  1m 15s ETA:  0s
info: downloading component 'rustfmt'
  4.1 MiB /   4.1 MiB (100 %) 817.5 KiB/s in  5s ETA:  0s
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
 18.3 MiB /  18.3 MiB (100 %)   1.5 MiB/s in 10s ETA:  0s
info: installing component 'rust-std'
 26.1 MiB /  26.1 MiB (100 %)   7.3 MiB/s in  3s ETA:  0s
info: installing component 'rustc'
 54.3 MiB /  54.3 MiB (100 %)   8.9 MiB/s in  6s 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"
  • After the installation, activate the Rust environment using the commands below.
source ~/.profile
source ~/.cargo/env
  • Next, add the rust compiler to your system using the command below.
sudo apt install rustc
  • You can check the version of Rust installed using the command below.
rustc -V

Sample Rust application

  • Create a directory for the sample application.
sudo mkdir ~/demo-project
  • Navigate to the created directory using the command below.
cd ~/demo-project
  • Then create a sample app using the following command.
sudo nano hellodemo.rs
  • Paste the code below into the file created above then save(ctrl+s) and close(ctrl+x) the file.
fn main() {
println!("Hello from itnixpro.com");
}
  • Next, compile the sample app using the following command.
rustc hellodemo.rs
  • To run the compiled program, use the command below.
./hellodemo

Update Rust on Ubuntu 22.04

  • Run the command below to update the Rust programming language.
rustup update

Uninstall Rust on Ubuntu 22.04

  • Use the following command to remove Rust from your system.
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
  • That marks the end of our article, we have gone through how to install Rust on Ubuntu 22.04.

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