Categories: Ubuntu

How to Install Rust on Ubuntu 22.04

“Are you looking for how to install Rust on Ubuntu 22.04? Rust is an open-source programming language that offers memory safety, speed, and parallelism. Rust offers a better approach to creating various applications, including operating systems, game engines, browser components, file systems, etc.

Today’s guide presents a comprehensive tutorial on installing Rust on Ubuntu 22.04 and creating your first Rust program.”

Step-by-Step Installation of Rust on Ubuntu 22.04

If you’ve not tried Rust on Ubuntu, we will see the steps for importing and installing Rust on Ubuntu 22.04 and offer an introduction to interacting with its terminal to create a simple Rust program. Let’s check out the required steps.

    Sponsored
  1. Update Your System

Before we get to the installation of Rust, first update your Ubuntu system to get the latest version of packages and eliminate dependency issues by running the command below.

$ sudo apt update && sudo apt upgrade

  1. Install Rust Dependencies

For a successful installation of Rust, various packages should be installed on your system. So, use the command below to install all the needed dependencies.

$ sudo apt install -y curl gcc make build-essential

  1. Download and Install Rust

Once you have the required dependencies installed, we must download the Rust installation scripts using curl. Note that we are using the rustup shell script, which is the recommended way of installing Rust on Ubuntu. Use the below command to download and start the Rust installer.

$ curl https://sh.rustup.rs -sSf | sh

You will be prompted to select the installation type for Rust during the installation. I recommend using the default option unless you understand the rustup installer.

So, enter 1 to select the default option and press the Enter key to continue the installation.

Wait for the installation to complete; the duration depends on your server’s internet speed. Once the installation completes, you will be notified that Rust is installed, as in the image below.

At this point, you must now configure your current shell for the Rust environment. The below commands will activate the environment.

$ source ~/.profile

$ source ~/.cargo/env

  1. Verify Rust Installation

Once you’ve activated the environment for Rust, confirm that the installation was a success by checking its version using the below command.

$ rustc -V

Sponsored

We can confirm that we have Rust installed, and for our case, the installed version is 1.64.0

  1. Creating a Simple Rust Program

So far, we’ve installed Rust and verified its installation. However, we can still create a simple Rust program to test the installation. The first thing to do when working with Rust is to create a workspace for your project.

Therefore, let’s create a directory using the below command. You can create your workspace in any location on your system.

$ mkdir ~/rust-demo

Next, navigate the created directory and use an editor to create a Rust file. In this case, we are using nano editor, and our file is linuxhint.rs

$ cd rust-demo && nano linuxhint.rs

With your Rust file opened, let’s create a simple hello world Rust program, as shown in the image below.

Save the file by pressing ctrl + 0 and exit by pressing ctrl + x.

The next thing is to compile the Rust file using the rustc command.

$ rustc linuxhint.rs

Once compiled, create your executable file and execute it, as in the case below.

$ ./linuxhint

Bingo! You’ve created your first Rust program on Ubuntu 22.04

With Rust up and running on your Ubuntu 22.04, proceed to create other Rust projects for your activities. Note that if you wanted to remove Rust from your Ubuntu 22.04, the below command would work for your case.

$ rustup self uninstall

Conclusion

Rust offers a faster and more lightweight option for building applications. We’ve seen the steps to follow to install Rust on Ubuntu 22.04 and create a simple Rust program. Thanks to this guide, you can now work on Rust projects on your Ubuntu 22.04.

Ubuntu Server Admin

Recent Posts

Canonical Releases Ubuntu 25.04 Plucky Puffin

The latest interim release of Ubuntu introduces “devpacks” for popular frameworks like Spring, along with…

2 days ago

Ubuntu 25.04 (Plucky Puffin) Released

Ubuntu 25.04, codenamed “Plucky Puffin”, is here. This release continues Ubuntu’s proud tradition of integrating…

3 days ago

Extended Security Maintenance for Ubuntu 20.04 (Focal Fossa) begins May 29, 2025

Ubuntu released its 20.04 (Focal Fossa) release 5 years ago, on March 23, 2020. As…

3 days ago

Ubuntu 20.04 LTS End Of Life – activate ESM to keep your fleet of devices secure and operational

Focal Fossa will reach the End of Standard Support in May 2025, also known as…

4 days ago

Ubuntu MATE 25.04 Release Notes

Ubuntu MATE 25.04 is ready to soar! 🪽 Celebrating our 10th anniversary as an official…

4 days ago

Ubuntu Weekly Newsletter Issue 887

Welcome to the Ubuntu Weekly Newsletter, Issue 887 for the week of April 6 –…

6 days ago