Introduction
Rust or rust-lang is a general-purpose programming language for system-level development projects. Rust is known for its speed, memory efficiency, seamless integration with other languages, and type safety.
This guide will teach you how to install Rust on Ubuntu using the apt package manager or curl.
Prerequisites
- Ubuntu system (This tutorial uses Ubuntu 20.04).
- Sudo privileges.
- Access to the command line.
Option 1: Install Rust on Ubuntu Using apt
The rustc package is included in the official Ubuntu repository, and Rust can be installed with the apt
package manager. Even though it may not offer the latest available version, using apt to install Rust is a simple and fast option.
Step 1: Update the Package Registry
First, update the system packages registry with:
sudo apt update
Step 2: Install Rust
After updating the package registry, install Rust by running the following command:
sudo apt install rustc
Type y when prompted and wait for the installation to complete.
Step 3: Verify the Installation
Confirm the installation with:
rustc -V
The command confirms the installation of rustc 1.61.
Option 2: How to Install Rust on Ubuntu Using rustup
To get the latest available version of Rust, use the curl command to download the rustup shell script. The rustup tool allows users to manage Rust in a more straightforward way.
Step 1: Download rustup
To download and install the rustup installer script, use the curl
command:
curl https://sh.rustup.rs -sSf | sh
Note: If you receive a "curl command not found" error message, it is likely that the curl package is not installed on your system. Install it by running sudo apt install curl
.
2. Type 1 to proceed with the default installation.
3. Restart the shell if necessary. (The system might not recognize the /.cargo/bin directory.)
Step 2: Add Rust to PATH
Once the shell reboots, run the following to add Rust to the system PATH:
source "$HOME/.cargo/env"
The command doesn't produce any output.
Step 3: Verify the Installation
Execute rustc
with the -V
argument to confirm the installation.
rustc -V
The output shows Rust version 1.65., a more up-to-date version than the one in the repository.
How to Uninstall Rust on Ubuntu
Depending on which method you used to install Rust, use either apt or the rustup tool to uninstall it.
Uninstall Rust Using apt
To uninstall Rust using the apt package manager, run:
sudo apt remove rustc
Confirm with y when prompted. To verify Rust is removed, run rust -V
:
The output shows that the package is not on the system.
Uninstall Rust Using rustup
To remove Rust from the system, execute:
rustup self uninstall
Hit y when prompted. When the process completes, check the Rust version to verify the outcome:
Conclusion
After reading this tutorial, you now know how to install Rust on Ubuntu, either with apt
or the Rustup installer. Next, check out this list of the best Linux text editors for coding.