How to Set Up a Rust Development Environment on Linux

According to Stack Overflow’s Developer Survey 2022, Rust has been the most-loved programming language for the last seven years. It’s safe, efficient, and versatile for handling applications of all levels of complexity, from system programming to chatbots and more.

If you haven’t had the chance to start developing in Rust yet, you should start by setting up a Rust development environment on Linux.

4

Prerequisites to Install Rust on Linux

Before you install Rust, you need to install one dependency: thebuild-essentialpackage. Why? Because Rust needs a linker to link all object files produced by the Rust compiler into an executable binary. The build-essential package contains a linker that’ll get the job done.

Here’s the command to install the build-essential package on Linux:

A Rust logo superimposed on a photograph of somebody working on an iMac desktop computer

For Arch Linux, run:

After you have finished installing the package, move on to installing Rust.

installing rust via rustup-1

Installing Rust on Linux

Rust is super easy to install and set up. All you need to do is run one single script that will install and set up everything for you.

The best thing is that this is the prescribed way to go, and the official Rust devs have developed the script, so you know you’re not running shady software on your system.

creating a new project with cargo

Here’s the command to install and run the rustup script:

This command will usethe curl commandto download the script and run it using theshcommand. Type in1when prompted.

running your rust porject with cargo

After a while, the script will finish and ask you toupdate the PATH variableto include the Cargo bin directory. You can do that usingthe source command:

Setting Up and Writing “Hello, World” in Rust

Rust’s build system, Cargo is a resourceful tool that helps you bootstrap, organize, and test your code with a few commands. To set up a new Rust project, run this command:

This command will set up a directory structure for a basic project and add amain.rsfile containing code for a “Hello, World” program inside the//srcdirectory. you’re able to either compile this code manually with the rustc compiler or use Cargo to run it:

Alternatively, here’s the syntax to use rustc to compile the code manually:

Kick Off Your Programming Journey as a Rustacean!

Now that you’ve installed and set up Rust on your Linux system, it’s possible to focus on learning and developing all sorts of programs with Rust.

If you’re absolutely new to Rust and are looking for a quick primer to get a feel for the language and its syntax, an introductory guide to Rust programming essentials will be of use.

Rust is a powerful language, but where to begin? If you’re used to another language, you’ll want to know how Rust deals with these familiar concepts.

Sometimes the smallest cleaning habit makes the biggest mess.

The best features aren’t the ones being advertised.

Your phone is a better editor than you give it credit for.

Goodbye sending links via other apps.

Some subscriptions are worth the recurring cost, but not these ones.

Technology Explained

PC & Mobile