You’re reading the article: How to install Rust by InApps Technology

Rust or also known as rust-lang is a general programming language for system-level development projects. Rust is well known for being speedy and can be integrated seamlessly with other programming languages.

The following article will cover Rust installation with careful easy-to-follow instructions.

Rust without Installation

The first thing I learned is that the Rust ecosystem is surprisingly robust — and that it’s possible to run Rust code without even installing anything. There’s a browser-based online “Rust Playground” where you can mess around with the language yourself. It starts you off with a pre-written “Hello world!” program, and dares you to take it from there.

 Hello World at Rust playground

That page features a lot of bells and whistles. The three dots on the far right pull up a menu that lets you select which Rust to run — either the earlier 2015 edition or the 2018 edition — and whether or not you want to enable a debugging backtrace when it executes to give you even more visibility into how the program runs.

There’s also a down-pointing arrow that brings up a menu for choosing which version of Rust to run — the current stable version, or the “beta” version (a more-recent version that gets updated every six weeks, according to the official Rust blog).

And in addition, every 24 hours the last successful new build becomes the new “nightly” build, to “give early adopters access to unfinished features as we work on them.” This is also available through the same menu (via that down-pointing arrow).

But even the playground’s “Run” option has several choices. One choice lets you compile your code without running it — with or without testing it for errors — or to convert it to Assembly or to WebAssembly.

And other choices let you convert your code to MIR (Rust’s “Mid-level Intermediate Representation”) or to LLVM IR (the intermediate representation for the Low-Level Virtual Machine that Rust uses as its backend).

Read More:   Strong Security Doesn’t Have to Equate to Slow Development – InApps 2022

It’s fun to see how their simple “Hello World” program expands with each selection.

Some Hello World code in Assembly

But of course you can also create your own local installation of Rust, and Rust has its own installer/version management tool — called rustup.

It’s available at Rust-lang.org on a slick web page that helpfully detects your operating system, and suggests the appropriate download.

Although if you access the page using the command-line browser Lynx in the Windows Subsystem for Linux, it apparently gets very confused, and displays messages for three different operating systems…

Rust install instructions via Lynx

rustup is officially described as a “toolchain multiplexer” that installs several of the important Rust tools. For example, rustup comes in handy when it’s time to update to a newer version of Rust. Just type:

rustup update

Rustup’s official documentation calls this “the essence of rustup”. But another neat thing about rustup is it makes it easy for you to manually switch between those three versions of the Rust compiler — the stable, beta, and nightly versions.

And if you want to make sure your rustup tool is up to date, you type…

rustup self update

So it seems deceptively simple to install Rust on a Windows system. You just download and run a file named Rustup-Init.exe

But of course, it wasn’t that easy…

Installation and a Detour

rustup checks for the necessary prerequisites, and lets you know if anything’s missing. In my case, I also needed to install the Microsoft C++ Build Tools — but Rustup-Init.exe told me I could get them by installing Microsoft’s Visual Studio IDE and then making sure that it also installed the C++ build tools — and even gave me the appropriate URL.

Rust install wants Microsoft C plus plus build tools
You can select the installation of build tools from Visual Studio’s workspace screen — although downloading them takes several long minutes…

The Visual Studio Installer alone was 67 megabytes, and Visual Studio Build Tools 2019 required 1.15GB more on my laptop — and took nearly 12 minutes to install. (It seemed to stall at page 83 of 89 pages installed — 35% of the status bar — and then suddenly shot up to 96%.)

Read More:   Sonatype Lift, a Deep Code Analysis Platform – InApps Technology 2022

Installing build tools with Visual Studio Installe

And when it was finished, a reboot was required.

But one reboot later, and I was running rustup

Getting Started With Cargo

The second thing I learned about Rust is there are a couple of parts to it — leading to one more very important part of the installation process.

rustup also installs the Cargo tool, which will launch the compiler for your code, run your code, and serve as a handy package manager for importing modules of pre-written Rust code — which will make everything easier. (And according to Rust’s official “Getting Started” page, Cargo also makes it easier to test your code, and to write documentation for it.)

For the Windows version, rustup also adds the corresponding commands to your PATH environment variables — rustup, cargo, and rustc (the compiler).

Launching a command window, I ran the compiler’s --version command to prove that yes, it’s been installed. And there it was!

Rust version check

But if I’ve learned anything as a programmer, it’s that it’s never simple to write a “hello world” program in a compiled language.

With Rust, first, you have to create a new hello_world package (according to the documentation in Rust’s official Cargo Book.) It has a chapter titled “First Steps with Cargo.”

This can be done easily with a single Cargo command…

cargo new hello_world

Creating that package means creating a directory named hello_world with a manifest file (named Cargo.toml) which holds key-value pairs for the name, version, author, and edition of my humble “hello world” program.

making hello_world package

When running the compiler, it will look for a Cargo.toml file in your current directory to tell it which program to compile. (And it will stop with an error if the file isn’t found.).

You don’t even have to specify the name of the program — it’s in the manifest. So just being in the appropriate directory is enough. You just type cargo build.

building hello world (cropped).

That cargo new command also created a separate src subdirectory where the actual code will go. I thought I was going to have to type in some lines of code (to print out “hello world” on my screen) — but apparently not.

Read More:   Celebrate National No-Code Day Today – InApps Technology 2022

Cargo created a main.rs file in my src directory which already contains an entire main function — and which already includes the appropriate print statement.

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

Did Cargo guess that since I was making a package named “hello_world,” I must want it to print out “hello world”?

No. It’s apparently the default stub that appears in every src directory’s main file. I tested this by creating a package named goodbye_world — and Cargo still included the exact same code in the main file it created. (Including a println statement that prints out “Hello, world!”)

So it’s a feature, not a bug — and the pre-written code now stares tantalizingly from my hard drive, daring me to finally compile it into my first executable Rust program. (Or, as the Cargo book explains, “Cargo generated a ‘hello world’ for us. Let’s compile it.”)

A Surprise Ending

Er, and unfortunately, here’s where the Cargo Book failed me. It told me that to run the program, I simply needed to type:

./target/debug/hello_world

Nope.

Rust error - not recognized

Fortunately, the Cargo Book also provides an alternate (and simpler) way of running Rust programs: just type cargo run in the appropriate directory — which will compile and run your program, all in one glorious step.

Hello World run from Rust on a Windows command line

It was glorious.

I did the building-and-running command a few more times, just because I could, just to prove to myself that it was really working.

And to savor the fact that I was finally running my very first Rust program…

How to uninstall Rust

If at any point you would like to uninstall Rust, you can run rustup self uninstall. The program will be automatically uninstalled from your device.

About InApps

InApps is an outsourcing and development company located in Vietnam. At InApps, we currently provide services on DevOpsOffshore Software DevelopmentMVP App Development, and Custom App Development. 

We’ve become a trusted partner of more than 60+ businesses from the US, the UK, and Europe to Hongkong from different industries.

More than being a partner, we aim to become the business’s companion. Therefore we continue to update helpful articles for those who are in need. 

Rate this post
As a Senior Tech Enthusiast, I bring a decade of experience to the realm of tech writing, blending deep industry knowledge with a passion for storytelling. With expertise in software development to emerging tech trends like AI and IoT—my articles not only inform but also inspire. My journey in tech writing has been marked by a commitment to accuracy, clarity, and engaging storytelling, making me a trusted voice in the tech community.

Let’s create the next big thing together!

Coming together is a beginning. Keeping together is progress. Working together is success.

Let’s talk

Get a custom Proposal

Please fill in your information and your need to get a suitable solution.

    You need to enter your email to download

      [cf7sr-simple-recaptcha]

      Success. Downloading...