How to Install Rust on Ubuntu

Introduction

Rust is a general-purpose programming language for system-level development projects. It is fast, memory efficient, and seamlessly integrates with other languages.

This guide will show you how to install Rust on Ubuntu using an installer script or the APT package manager.

How to Install Rust on Ubuntu.

Prerequisites

Option 1: Install Rust on Ubuntu Using rustup

Use the rustup shell script to install the latest version of Rust. The script allows users to customize their Rust installation by specifying the default host triple, toolchain, and profile.

Follow the steps below to install Rust with rustup.

Step 1: Start rustup

Use the following procedure to download and initiate the rustup script:

1. Enter the curl command below:

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

The Rust installer starts.

The welcome message produced by the rustup script.

2. Press Enter to proceed with the default installation.

The rustup script installation options.

Note: To customize the default installation parameters, type 2 and press Enter.

Wait for the installation to finish. Once Rust is installed, the output confirms the success of the operation.

Rust installation with rustup is complete.

Note: The system might not recognize the /.cargo/bin directory. To resolve the issue, exit the current Terminal instance and start a new one.

Step 2: Add Rust to PATH

Run the following source command to add Rust to the system PATH:

source "$HOME/.cargo/env"

The command does not produce an output.

Step 3: Verify Installation

Execute rustc with the -V option to verify the installation:

rustc -V

The output shows the installed Rust version.

rustc -V terminal output when Rust is installed via rustup.

Option 2: Install Rust on Ubuntu Using APT

The official Ubuntu repository contains the Rust package, which means Rust can be installed with the APT package manager. Even though it does not offer the latest version, using APT to install Rust is a simple and fast option.

Use the steps below to install Rust via APT.

Step 1: Update Package Registry

Refresh the list of package sources by entering the following:

sudo apt update

This action ensures that APT installs the latest Rust version available in the repositories.

Step 2: Install Rust

After updating the package registry, install Rust by running the following command:

sudo apt install rustc

Enter Y when prompted and wait for the installation to complete.

Installing Rust via APT.

Step 3: Verify Installation

Confirm the installation using the rustc command:

rustc -V

The output shows the version of Rust installed on the system.

rustc -V terminal output installed via apt

How to Uninstall Rust on Ubuntu

Depending on which method you used to install Rust, use either the rustup or apt command to uninstall it:

  • Remove a rustup version from the system by executing:
rustup self uninstall

Enter Y to confirm the action and wait for the removal to finish.

Uninstalling Rust installed via rustup.
  • Uninstall an APT version of Rust by running:
sudo apt remove rustc

Enter Y to confirm. APT removes Rust from the system.

Uninstalling Rust installed via APT.

Conclusion

After reading this tutorial, you know how to install Rust on Ubuntu. The article covered the installation methods that involved the APT package manager and the rustup script installer.

Next, check out this list of the best Linux text editors for coding to find a suitable tool for writing Rust code.

Was this article helpful?
YesNo
Sara Zivanov
Sara Zivanov is a technical writer at phoenixNAP who is passionate about making high-tech concepts accessible to everyone. Her experience as a content writer and her background in Engineering and Project Management allows her to streamline complex processes and make them user-friendly through her content.
Next you should read
How to Reinstall Ubuntu
July 6, 2022

This tutorial shows how to create a bootable USB and reinstall Ubuntu. Reinstalling the OS is sometimes the easiest solution for fixing issues with drivers or after an upgrade failure...
Read more
How to List Installed Packages on Ubuntu
March 9, 2022

Having a precise list of installed packages helps system admins maintain, replicate, and reinstall systems. In this tutorial, learn...
Read more
How to Install Ubuntu 22.04 LTS Desktop (Jammy Jellyfish)
April 20, 2022

Ubuntu 22.04 LTS is the newest Ubuntu version with great new features. Follow this guide to install Ubuntu 22.04...
Read more
How to Fix Broken Packages in Ubuntu
October 14, 2021

A bad internet connection or misconfigured third-party installers can corrupt packages and cause problems on your computer. This article will show...
Read more