Executive Education

How To Install The Rust Programming Language On Linux

Rust was developed by Mozilla, originally released on July 7, 2010, and designed for highly concurrent and safe systems. The syntax of Rust is similar to C and C++, with blocks of code delimited by curly braces ({}). The emphasis of Rust is safety, control of memory layout, and concurrency.

Rust is currently being employed by companies like Dropbox, Sentry, Postmates, Brilliant, Tonsser Stac, Wantedly, Klarna, Doctolib, QIWI, and software development companies like BairesDev. Rust seamlessly integrates with tools like Google Code, Ethereum, Iron, Ripple, Leaf, Tokamak, Pencil, and Airbrake.

The Rust language supports zero-cost abstractions, threads without data races, trait-based generics, and pattern matching. It’s also fast, has a minimal runtime, supports algebraic data types, includes efficient C bindings, and is open source. Those new to Rust will need to install the programing language on a supported platform.

Although there are a number of operating systems Rust can be used on, chances are you’ll be developing with Rust on Linux, especially for web-based applications and services. So let’s walk through the process of installing Rust on Linux. I’ll show you how to install this programming language on Debian/Ubuntu and CentOS/RHEL. Once installed, you can start your development journey to create world-class applications and services.

What You’ll Need

The only things you’ll need to get Rust installed are:

  • A running Linux distribution.
  • A user with sudo privileges.
  • A network connection.

That’s it. Let’s install it.

Update/Upgrade

Before we jump into the installation of Rust, let’s update and upgrade our system. Just remember that if the kernel gets upgraded, you’ll need to reboot the machine. Because of this, make sure to run the update/upgrade process at a time when a reboot is possible.

Once you have the time set, you can upgrade the different distributions like so.

Debian/Ubuntu with the commands:

sudo apt-get update

sudo apt-get upgrade -y

CentOS/RHEL with the command:

sudo dnf update -y

If required, reboot and log back into your machine.

Installing Rust

Now, we can install Rust. In order to do so, we must first install the curl application. This can be done on the various distributions with the following commands.

Debian/Ubuntu:

sudo apt-get install curl -y

CentOS/RHEL:

sudo dnf install curl -y

With curl installed, download and run the Rust installation script with the command:

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

Once the installer has downloaded it will automatically run and ask you if you want to proceed, customize, or cancel the installation (Figure 1).

Figure 1

Proceeding with the installation.

Type 1 to proceed with the installation. During the process, rustup will attempt to add Cargo’s bin directory to your $PATH. Chances are it will fail, so you’ll have to do it manually. To add the Cargo bin directory to your $PATH, issue the command:

source $HOME/.cargo/env

You also need to source ~/.profile to use the modified $PATH and ensure your shell will work with the rust environment. Do this with the command:

source ~/.profile

Once you’ve taken care of that, log out and log back into your machine and verify the rust installation by issuing the command:

rustc –version

You should see the version of Rust printed in the output (Figure 2).

Figure 2

Rust has been successfully installed.

Finally, you’ll need to install the required dependencies for the rustc command. Here’s how you do that on the various distributions.

Debian/Ubuntu:

sudo apt-get install build-essential -y

CentOS/RHEL:

sudo dnf install cmake gcc -y

Testing Rust

If you’re an application development company, it’s not enough to just install the programming language. You need to test the Rust installation by creating a simple program. We’ll create the tried and true “Hello, World!” application.

First, create a new directory for the program with the command:

mkdir rusttest

Change into that new directory with the command:

cd rusttest

Create a new file with the command:

nano rusttest.rs

Paste the following into that file:

fn main() {

println!(“Hello, World!”);

}

Create the Rust executable with the command:

rustc rusttest.rs

You will not see any output from the above command. You should, however, see a new executable application in the rusttest directory, called rusttest. To run that executable application, issue the command:

./rusttest

When you execute the application, Hello, World! should print out on your screen (Figure 3).

Figure 3

A successful test of Rust.

And that’s all there is to installing Rust and creating your first program. Congratulations, your journey is just beginning. You’ll soon be creating powerful and helpful applications used by your company or end-users around the globe.


Have you read?

World’s Happiest Countries.
Countries With The Highest Life Expectancy.
World’s Most (And Least) Religious Countries.
World’s Best Countries For Investment In Travel And Tourism Sector.

Ryan Miller

Ryan Miller

Global Assignment Editor
Ryan Miller is the Global Assignment Editor at CEOWORLD magazine. He covers anything and everything related to CEOs, CFOs, CIOs, senior management executives, business leaders, and high net worth individuals worldwide, whether lists or lifestyle, business or rankings. During his five-year tenure at CEOWORLD magazine, he has employed his expertise in data science across several roles. Ryan was previously responsible for data modelling and analytics, as well as secondary research, on the CEOWORLD magazine Custom Research team. He can be reached on email ryan-miller@ceoworld.biz. You can follow him on Twitter at @ceoworld.