How to install Rust in Linux?


Rust (OR Rust-Lang) is a general-purpose, fast, and memory-efficient programming language which is developed by Graydon Hoare at Mozilla Research. Syntactically it is similar to C++ but it can guarantee memory safety by using a borrow checker to validate references.

With no runtime or garbage collector, it can power performance-critical services, run on embedded devices. It can easily integrate with other programming languages.

In this article, I will discuss how to install the Rust programming language in Linux.

The features of the Rust programming language

The key features of the Rust programming language are –

  • Rust is designed to be memory safe, it does not permit null pointers, dangling pointers, and data races in safe code.
  • It has a better memory management mechanism.
  • It has an ownership system where each value has a unique owner and the scope of a value will be the same as its owner.
  • Rust supports types system which is a mechanism similar to type classes called traits. It is a facility for ad-hoc polymorphism

Install the curl utility

The official way to install Rust on a Linux system is to use the installer script. To download it you should have curl utility installed on your system.

If your system already have curl installed then you can skip the installation process of curl.

Based on the distribution that you are using use one of the given commands to install curl utility on your system.

On Ubuntu, Linux Mint, Debian, etc use –

sudo apt install curl

If you are using RHEL, CentOS or Fedora then use –

sudo dnf install curl

If it asks for confirmation press y and then enter to proceed with the installation process.

Installing Rust in a Linux system

After installing the curl command use the given command to download and install the Rust on your system.

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

You will be prompted some options press and then enter. This will start downloading Rust language components.

Now once the Rust installation is complete the Cargo’s bin directory i.e. ~/.cargo/bin will be added to your PATH environment variable, in /.profile.

The next step is to restart your current shell or source the ~/.profile to use modified PATH –

source ~/.profile

And configure your current shell to work with the rust environment variable –

source ~/.cargo/env

Verify the installation of Rust

After completing the above steps you can use the given command to verify the installation of the Rust programming language on your Linux system.

rustc --version

Run hello world program in Rust

First, save the given code in a file with the .rs extension.

fn main() {
    println!("Hello, World!");
}

First, use the given command to create an executable of this code.

rustc hello.rs

Finally, execute the code using –

Update Rust on your system

To ensure that you get the latest features and functionalities of Rust on your system you need to update it. At any time you can update Rust on your system using –

rustup update

Uninstall Rust from your system

For any reason, if you want to remove it from your system then you can do this by using the given command –

rustup self uninstall

Ok, that’s all for now. I hope you have successfully set up Rust in your Linux system. For any query, you can write us in the comments below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.