How to Install Rust on Ubuntu
Posted on
Rust, also known as rust-lang, is a programming language designed for system-level development projects. Rust is well-known for its speed, memory efficiency, easy integration with other programming languages, and type safety.
This tutorial will show you how to install Rust on Ubuntu with the apt package manager or curl.
Prerequisites
- Ubuntu operating system (This tutorial uses Ubuntu 20.04).
- Sudo access.
- Command-line access.
Option 1: Download and install Rust on Ubuntu, making use of apt
Rust can be installed using the apt package manager, and the rustc package is included in the official Ubuntu repository. Even if it does not provide the most recent version, using apt to install Rust is a simple and quick option.
First, update the Package Registry.
To begin, modify the system packages registry with:
sudo apt update

Second: Set up Rust
After updating the package registry, run the following command to install Rust:
sudo apt install rustc

When prompted, enter y and wait for the installation to finish.
Third: Examine the Installation
Confirm the installation by typing:
rustc -V

The command confirms that rustc 1.61 has been installed.
Option 2: Installing Rust on Ubuntu making use of rustup
Use the curl command to download the rustup shell script to get the most recent version of Rust. Users can use the rustup tool to manage Rust in a more straightforward manner.
Step 1: Get rustup.
Use the curl command to download and install the rustup installer script:
curl https://sh.rustup.rs -sSf | sh

NB: If you receive a “curl command not found” error message, your system most likely lacks the curl package. Install it with sudo apt install curl.
To continue with the default installation, type 1.

If necessary, restart the shell. (The /.cargo/bin directory may not be recognized by the system.)

Step 2: Include Rust in your PATH.
After the shell has rebooted, run the following commands to add Rust to the system PATH:
source "$HOME/.cargo/env"

There is no output from the command.
Step 3: Examine the Installation
To confirm the installation, run rustc with the -V argument.
rustc -V

The output shows Rust version 1.65, which is more recent than the version in the repository.
How to Remove Rust from Ubuntu
To uninstall Rust, use either apt or the rustup tool, depending on how you installed it.
Uninstall Rust Using apt
Run the following command to uninstall Rust using the apt package manager:
sudo apt remove rustc

When prompted, confirm with y. Run rust -V: to ensure that the rust has been removed.

The output indicates that the package is not present on the system.
Using rustup, uninstall Rust.
Run the following command to remove Rust from the system:
rustup self uninstall

When prompted, press y. When the process is finished, check the Rust version to confirm the result:

Conclusion
After finishing this tutorial, you should be able to install Rust on Ubuntu using either apt or the Rustup installer.