How to Install ERPNext on Rocky Linux 9 3

How to Install Rust on Ubuntu 22.04

Looking for a programming language, you can run on Linux that offers a better approach to creating various applications, game engines, browser components, and more? In this article, we will discuss How to Install Rust on Ubuntu 22.04.

An open-source systems programming language called Rust strongly emphasizes parallelism, speed, and memory safety. Rust is a programming language that developers utilize to build various innovative software applications and software development projects, from virtual reality simulation engines, operating systems, file systems, gaming engines, to browser components.

Although Rust and C++ share a similar syntax, Rust uses a borrow checker to validate references, which ensures memory safety. The strong general-purpose programming language Rust, also referred to as rust-lang, was created by Mozilla and was designed by Graydon Hoare.

Its user base is growing every day due to its simplicity in integrating seamlessly with other languages.

How to Install Rust on Ubuntu 22.04

The instructions in this guide were created using Ubuntu 20.04 (Focal Fossa), but they are also applicable to earlier releases and other Linux distributions that are based on Debian/Ubuntu.

We suggest updating your system to ensure all current packages are updated before we start installing Rust on Ubuntu to prevent conflicts. To accomplish this, we must use the apt package management service to update our default repositories.

Open the terminal on your Ubuntu computer and enter the following commands to complete this.

Syntax:

$ sudo apt update
Image shows command to update apt.

On your screen, you should see an output that looks like this. The upgrade command will then be used in our Terminal.

Syntax:

$ sudo apt upgrade
Image shows command to upgrade apt.

To continue with the operation, type “Y” in the command line. Now, when we install Rust on Ubuntu Linux, we will have all the most recent repositories.

Installing Dependencies for rust on Ubuntu 22.04

Run the following command to install the necessary packages for installing and successfully running Rust on your system before continuing. The packages are well-known and widely utilized in other installations of a similar nature.

Syntax:

$ sudo apt install curl build-essential gcc make -y
Image shows command to install curl build-essential.

Run the command even if you are unsure because it won’t hurt you.

Install Rust on Ubuntu 22.04

It’s time to install Rust on Ubuntu now that we’ve discussed the prerequisites and the Rust programming language. The actions below must be followed to accomplish this.

Using the RustUp Script, install Rust on Ubuntu

Rust can be installed on Linux in various ways, although the rustup shell script is the most suggested one.

On the official Rust website, this is the method that is advised for installing Rust on Ubuntu. So, in this tutorial, this would be the approach we would take. We must type the following command into our terminal to use the rustup installation.

Syntax:

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

Or

$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

After that, you ought to receive a popup asking whether you want to install the default settings or customize them, similar to the output in the example below.

Image shows command to install rust.

When you execute this command, you ought to get a screen with output like the one below. You will have the option to select the installation type you desire.

Select the second option if you are familiar with the rustup installer and want to personalize your installation. For the purposes of this tutorial, we will, however, just select the first option that is set to default and press Enter.

Image shows output when installing rust.

Please be aware that your current shell will need to have the (Rust environment) activated. To enable the rust environment, use the command shown below:

Syntax:

$ source ~/.profile
$ source ~/.cargo/env

or

$ source $HOME/.cargo/env
Image shows command to activate rust.

Confirm the installation

Before using Rust on our system, we must validate the installation of Rust after it has been installed on Linux.

By requesting the version of the Rust programming language that is currently installed on our system, we can confirm this. We input this in our Terminal to accomplish this.

Syntax:

$ rustc --version

Or 

$ rustc -V
Image shows command to get rust version.

This will retrieve the Rust version that is currently installed on our system. The screenshot above shows version 1.43.1 of Rust, which is the most recent stable release as of the time this lesson was being created.

If you cannot print the version build, take note that the Rust environment shell is not activated.

We shall now examine Rust’s functionality. To do this, we’ll first use the following commands to establish a few directories for our Rust scripts.

Syntax:

$ mkdir ~/rust_projects
$ cd ~/rust_projects
$ mkdir test_dir
$ cd test_dir
Image shows how to prepare environment for rust.

This will produce a test directory inside the project directory and a directory for our Rust projects. Now, using nano or any other text editor of your choice, we’ll create a file to house our Rust code.

Syntax:

$ nano rust_test_file.rs
Image shows sample code for rust.

This is what you will see upon running the above command.

Note that all of your Rust scripts must end with the.rs extension. Enter the following test code when the file is opened, then save it by pressing “Ctrl + O”, then enter. Exit the nano by pressing “Ctrl + X”.

Code:

fn main() {
    println!("Congrats! Your Rust script is running");
}
install rust on ubuntu 22.04

After using the rustc command to compile the code, we will make a rust executable file in the same directory. Let’s use the next command to launch the executable file. If everything goes according to plan, we ought to have a result similar to the one shown above.

install rust on ubuntu 22.04

You were successful in installing Rust on Ubuntu if your test script functions. You can now start using the Rust programming language to create programs and scripts.

Error While Trying to Compile a Code

In case you get an error like “Error: linker ‘cc’ not found” when trying to compile your first code. 

install rust on ubuntu 22.04

You may want to try a few things, but try running the commands below.

Syntax:

$ sudo apt-get update 
$ sudo apt install build-essential
install rust on ubuntu 22.04

Type in “y” then hit enter to proceed with the installation of the build-essential.

Additional frequently used Rust instructions

The procedures for installing Rust on Ubuntu have been discussed. However, there are still two instructions that we need to talk about for your benefit. You should update your Linux Rust installation at regular intervals.

This is crucial to do to guarantee that you can access the most recent Rust features and functionalities on your system. Enter the following command in your terminal to accomplish this.

Syntax:

$ rustup update
install rust on ubuntu 22.04

You can decide to uninstall Rust from your system if you no longer want to use it. Use this command to remove Rust from your system along with any related repositories.

Syntax:

$ rustup self uninstall
install rust on ubuntu 22.04

Conclusion

A multi-paradigm programming language is called Rust. It was developed as a language for building effective and powerful programs. It is being used by more and more developers over time because of its open-source nature, support from Mozilla, and a passionate community, to name just a few factors.

In this guide, we assisted you on how to install Rust on Ubuntu 22.04. We showed you the steps needed to set up and activate your rust environment, compile your first code, and we also discussed what to do in case you get some error while trying to compile your first code.

If this guide helped you, please share it. ?

Leave a Reply
Previous Article
How to Create Microsoft Azure Virtual Machine Scale Sets

How to Create Microsoft Azure Virtual Machine Scale Sets

Next Article
glances fi

How to Monitor Your Server's Resource Consumption on Linux

Related Posts