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

Meet the Canonical Ceph team at Cephalocon 2024

Photo by Jeton Bajrami on Unsplash Date: December 4-5th, 2024 Location: Geneva, Switzerland In just…

52 minutes ago

The transition to in-house software development in the automotive industry

Who will win the race to the perfect SDV? The automotive industry is experiencing a…

54 minutes ago

Profile-guided optimization: A case study

Software developers spend a huge amount of effort working on optimization – extracting more speed…

55 minutes ago

Ubuntu Weekly Newsletter 866

Welcome to the Ubuntu Weekly Newsletter, Issue 866 for the week of November 10 –…

17 hours ago

Ubuntu vs Debian: Linux Distributions Compared Deep Dive

Debian and Ubuntu are two popular Linux distributions. In this deep dive we will guide…

1 day ago

How to Install Google Cloud BigQuery Python client library on Linux

In this article, we will see how to Install Google Cloud BigQuery Python client library…

3 days ago