How to Install Rust on Ubuntu (the Easy Way)


Rust is a programming language mainly associated with software development and is widely used on Ubuntu-enabled desktops. Rust draws its roots from C++ and promotes safety, concurrency, and speed. The programming language has made its niche in technology, especially in memory management.

You can safely use the language to develop gaming engines, browsers, and operating systems. If you’re an Ubuntu fan, you’ll probably want to use Rust on your favorite OS. We’ll show you how you can install Rust on Ubuntu.

How to Install Rust on Ubuntu

There are two ways to install Rust. The first method is to install the language via Ubuntu’s native package manager (APT). The second method uses the curl command.

Since many people don’t understand what is the curl command and how to use it on Linux, it is important not to undermine its usage capabilities.

Here’s how you can install Rust using both ways.

Method 1: Install Rust on Ubuntu Using APT

Before you begin installing Rust on your machine, you need to update your system using the update and upgrade commands:

 sudo apt update && sudo apt upgrade -y 
Ubuntu terminal window with update commands

Once the system is updated, it’s time to begin the installation. Install Rust with the following command:

 sudo apt install rustc 
Ubuntu terminal window with code snippets

Verify the installation by typing:

 rustc -V 

The output should list the Rust version number.

Version number on Ubuntu terminal window

Method 2: Install Rust on Ubuntu With rustup

An alternate option to install Rust on Ubuntu is using the rustup shell script, which you can install via the curl command. Before moving further with the installation, you need to install curl, especially, if it’s not installed on your system.

As a precursory check, you can check the curl version on your system. You don’t need to install curl if the output contains a version number.

Ubuntu terminal window with code snippets

However, if you get the following error message, you must install curl on Ubuntu.

 bash: /usr/bin/curl: No such file or directory 

To install curl on Ubuntu, run:

 sudo apt install curl -y 

It’s now time to install the Rust language on Ubuntu. To run the rustup script, type:

 curl -sSf | sh 
Ubuntu terminal window with code snippets

Type 1 when prompted to select the Proceed with Installation (default) option.

Ubuntu terminal window with code snippets

Restart your terminal and pass the following command to add Rust to your system’s PATH:

 source "$HOME/.cargo/env" 

Since this won’t return an output, use the following command to verify the installation:

 rustc -V 

The output will return a version number, which is an installation confirmation.

How to Uninstall Rust on Ubuntu

You can uninstall Rust on Ubuntu via two methods, similar to how you installed Rust using APT and the rustup shell script.

Uninstall Rust via APT

You can use the APT remove command as follows:

 sudo apt remove rustc -y 

If you have installed Rust via the rustup shell script, but are keen to uninstall it using the APT commands, you can follow up the above command with the following to remove all dependent versions:

 sudo apt autoremove 

This will remove all the listed dependencies post-execution.

Apt command to remove rust package in Ubuntu

Remove Rust From Ubuntu Using rustup

Similar to APT, you can remove Rust using rustup on Ubuntu. You can remove it with the following command:

 rustup self uninstall 

Type y when it prompts for confirmation. As soon as you provide confirmation, you’ll get a list of elements that the tool will uninstall.

Ubuntu terminal window with code snippets

Working With Rust Programs on Ubuntu

Rust is a handy tool you can use within Ubuntu to write, compile, and execute complex scripts. Since this language doesn’t come pre-installed on Linux, it is necessary to understand how to install, access, and uninstall it on Ubuntu.

You can use plenty of Rust-based commands within various Linux distributions, making it easier for you to master the language and further champion your true potential in the programming world.


Source link

Leave a Reply

%d bloggers like this: