Kiến Thức Linux

How to Install Rust on Ubuntu

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.

How to Install Rust on Ubuntu

Prerequisites

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
sudo apt update terminal output

Step 2: Install Rust

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

sudo apt install rustc
sudo apt install rustc terminal output

Type y when prompted and wait for the installation to complete.

rust installing progress terminal output

Step 3: Verify the Installation

Confirm the installation with:

rustc -V
rustc -V terminal output installed via apt

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
curl install Rustup terminal output

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.

type 1 terminal output

3. Restart the shell if necessary. (The system might not recognize the /.cargo/bin directory.)

Restart shell terminal output

Step 2: Add Rust to PATH

Once the shell reboots, run the following to add Rust to the system PATH:

source "$HOME/.cargo/env"
Add Rust to PATH

The command doesn’t produce any output.

Step 3: Verify the Installation

Execute rustc with the -V argument to confirm the installation.

rustc -V
rustc -V terminal output installed via curl

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
sudo apt remove rustc terminal output

Confirm with y when prompted. To verify Rust is removed, run rust -V:

rustc -V terminal output uninstalled via apt

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
rustup self uninstall terminal output

Hit y when prompted. When the process completes, check the Rust version to verify the outcome:

rustc -V terminal output uninstalled via curl

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.

Đăng ký liền tay Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !

Add Comment

Click here to post a comment

Đăng ký liền tay
Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !