Cyberithub

How to Install Rust Programming Language in Linux Using 6 Best Steps

Advertisements

In this article, I will take you through the steps to install Rust Programming Language in Linux. Rust is a free and open source programming Language mainly focused on replacing low level coding languages like C/C++. It provides efficient memory management as compared to C/C++. It also provides the much needed feature known as Concurrency required to harness the benefits of latest System Architecture. Rust is type-safe language developed by Mozilla in 2010. It also provides added feature during Compile time as compared to other low level Languages like C/C++. Here we will go through the steps in detail to install Rust Programming Language in Linux.

How to Install Rust Programming Language in Linux Using 6 Best Steps 1

Install Rust Programming in Linux

Also Read: 6 Popular Examples of stat command in Linux/Unix for Beginners

Step 1: Prerequisites

a)You need to have a running Linux Based System(RHEL/CentOS).

b)You should have yum and curl tool installed in your System. You can check 20 Useful curl command in Linux with Examples | How to use curl in Linux to know more about curl command.

c)You need to have a sudo access to run privileged commands. You can check How to Add User to sudoers to know more about providing sudo access to the Users.

Step 2: Update Your System

Before going to install Rust Programming Language in Linux, it is imperative to install latest available updates in your System by using yum update -y command as shown below. This command will search and install the latest updates from the RHEL/CentOS Repository.

[root@localhost ~]# yum update -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 8.2 kB 00:00:00
* base: centos.excellmedia.net
* epel: mirrors.thzhost.com
* extras: centos.excellmedia.net
* updates: centos.excellmedia.net
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/4): epel/x86_64/group_gz | 95 kB 00:00:00
(2/4): updates/7/x86_64/primary_db | 2.9 MB 00:00:01
(3/4): epel/x86_64/updateinfo | 1.0 MB 00:00:01
(4/4): epel/x86_64/primary_db | 6.8 MB 00:00:03
Resolving Dependencies
--> Running transaction check
---> Package ca-certificates.noarch 0:2019.2.32-76.el7_7 will be updated
---> Package ca-certificates.noarch 0:2020.2.41-70.0.el7_8 will be an update
---> Package kernel.x86_64 0:3.10.0-1127.13.1.el7 will be installed
---> Package kernel-headers.x86_64 0:3.10.0-1127.10.1.el7 will be updated
---> Package kernel-headers.x86_64 0:3.10.0-1127.13.1.el7 will be an update
---> Package kernel-tools.x86_64 0:3.10.0-1127.10.1.el7 will be updated
---> Package kernel-tools.x86_64 0:3.10.0-1127.13.1.el7 will be an update
---> Package kernel-tools-libs.x86_64 0:3.10.0-1127.10.1.el7 will be updated
---> Package kernel-tools-libs.x86_64 0:3.10.0-1127.13.1.el7 will be an update
---> Package microcode_ctl.x86_64 2:2.1-61.6.el7_8 will be updated
---> Package microcode_ctl.x86_64 2:2.1-61.10.el7_8 will be an update
---> Package python-perf.x86_64 0:3.10.0-1127.10.1.el7 will be updated
---> Package python-perf.x86_64 0:3.10.0-1127.13.1.el7 will be an update
---> Package rsyslog.x86_64 0:8.24.0-52.el7 will be updated
---> Package rsyslog.x86_64 0:8.24.0-52.el7_8.2 will be an update
---> Package unbound-libs.x86_64 0:1.6.6-4.el7_8 will be updated
---> Package unbound-libs.x86_64 0:1.6.6-5.el7_8 will be an update
--> Finished Dependency Resolution
--> Running transaction check
---> Package kernel.x86_64 0:3.10.0-957.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
Package Arch Version Repository Size
========================================================================================================================================================================
Installing:
kernel x86_64 3.10.0-1127.13.1.el7 updates 50 M
Updating:
ca-certificates noarch 2020.2.41-70.0.el7_8 updates 382 k
kernel-headers x86_64 3.10.0-1127.13.1.el7 updates 9.0 M
kernel-tools x86_64 3.10.0-1127.13.1.el7 updates 8.0 M
kernel-tools-libs x86_64 3.10.0-1127.13.1.el7 updates 8.0 M
microcode_ctl x86_64 2:2.1-61.10.el7_8 updates 2.7 M
python-perf x86_64 3.10.0-1127.13.1.el7 updates 8.0 M
rsyslog x86_64 8.24.0-52.el7_8.2 updates 621 k
unbound-libs x86_64 1.6.6-5.el7_8 updates 406 k
Removing:
kernel x86_64 3.10.0-957.el7 @anaconda 63 M

Transaction Summary
========================================================================================================================================================================
Install 1 Package
Upgrade 8 Packages
Remove 1 Package

Step 3: Install Rust Programming Language in Linux

After successfully updating your System, it is now time to install Rust Programming Language using below curl command. Below curl command will install Rust Programming Language in Linux using rustup tool. It will download and install the Rust Programming Language Compiler known as Cargo. Once you run the below command it will ask you to select the option to proceed with the Installation.

You need to Select Option 1 to proceed with the steps to install Rust Programming Language in Linux. It will download all the required Rust Programming Language Components as shown below.

[root@localhost ~]# curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
info: downloading installer

Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

It will add the cargo, rustc, install rustup and other commands to
Cargo's bin directory, located at:

/root/.cargo/bin

This can be modified with the CARGO_HOME environment variable.

Rustup metadata and toolchains will be installed into the Rustup
home directory to install Rust, located at:

/root/.rustup

This can be modified with the RUSTUP_HOME environment variable.

This path will then be added to your PATH environment variable by
modifying the profile files located at:

/root/.profile
/root/.bash_profile

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:

default host triple: x86_64-unknown-linux-gnu
default toolchain: stable
profile: default
modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>1

info: profile set to 'default'
info: default host triple is x86_64-unknown-linux-gnu
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: latest update on 2020-06-18, rust version 1.44.1 (c7087fe00 2020-06-17)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
12.2 MiB / 12.2 MiB (100 %) 5.4 MiB/s in 2s ETA: 0s
info: downloading component 'rust-std'
17.7 MiB / 17.7 MiB (100 %) 5.7 MiB/s in 3s ETA: 0s
info: downloading component 'rustc'
60.3 MiB / 60.3 MiB (100 %) 4.0 MiB/s in 11s ETA: 0s
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
12.2 MiB / 12.2 MiB (100 %) 2.6 MiB/s in 4s ETA: 0s
info: installing component 'rust-std'
17.7 MiB / 17.7 MiB (100 %) 9.8 MiB/s in 1s ETA: 0s
info: installing component 'rustc'
60.3 MiB / 60.3 MiB (100 %) 7.8 MiB/s in 8s ETA: 0s
info: installing component 'rustfmt'
info: default toolchain set to 'stable'

stable installed - rustc 1.44.1 (c7087fe00 2020-06-17)

Rust is installed now. Great!

To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH
environment variable. Next time you log in this will be done
automatically.

To configure your current shell run source $HOME/.cargo/env

Step 4: Configure Rust Programming Language in Linux

After successful installation of Rust Programming Language Components, you can configure your current shell by running source $HOME/.cargo/env command. It will configure the current logged in User shell to run the Rust programs.

If you open ~/.profile and ~/.cargo/env file you will see bin path added in global environment variable $PATH. If it is not added you need to add it manually to make rust programming tool work.

[root@localhost ~]# source $HOME/.cargo/env
[root@localhost ~]# cat ~/.profile
export PATH="$HOME/.cargo/bin:$PATH"
[root@localhost ~]# cat ~/.cargo/env
export PATH="$HOME/.cargo/bin:$PATH"

Step 5: Check Rust version

After adding rust bin tools in $PATH you can check the rust tool version using rustc --version command as shown below. As you can see from below output, currently installed rustc version is 1.44.1.

[root@localhost ~]# rustc --version
rustc 1.44.1 (c7087fe00 2020-06-17)

Step 6: Test Rust Programming Language in Linux

It is now time to test the Rust Programming Language by writing a simple program as shown below. Let's create a directory example first and then go to that directory and create a file known as hello.rs. You can notice here that the Rust Program should be saved with .rs extension. Here we will write a simple print program to display "This is hello from CyberITHub" in the Standard Output.

[root@localhost ~]# mkdir example
[root@localhost ~]# cd example
[root@localhost example]# vi hello.rs
fn main()
{
println!("This is hello from CyberITHub");
}

After saving above program you need to compile it using rustc hello.rs command as shown below. If compilation is successful then you will see an executable file hello generated in the current directory. This executable needs to be run using ./hello command. Upon successful execution, it will display the output "This is hello from CyberITHub" as specified below.

[root@localhost example]# rustc hello.rs
[root@localhost example]# ls -lrt
total 2848
-rw-r--r-- 1 root root 58 Jun 28 14:02 hello.rs
-rwxr-xr-x 1 root root 2912208 Jun 28 14:02 hello
[root@localhost example]# ./hello
This is hello from CyberITHub

 

I hope you liked this article on How to Install Rust Programming Language in Linux. Please feel free to share your feedback on Comment Box.

 

Popular Recommendations:-

How to Install PHP on Ubuntu 18.04

How to Install PHP on RedHat/CentOS 7 with Easy Steps

How to Install Ruby on Ubuntu 18.04 with Easy Steps

How to Install Ruby on CentOS/RedHat 7 in 5 Easy Steps

Install NPM and Node.js in 6 Easy Steps on CentOS 7

Install Node.js in 6 Easy Steps on Ubuntu 18.04

How to Install NVM for Node.js on Ubuntu 18.04

How to Install Rust Programming Language in Linux

Install Rust Programming Language in Linux

Steps to Install Rust Programming in Linux

How to Install Rust Programming Language on Ubuntu

Leave a Comment