Rust Installation Guide

Beginner

This tutorial is from open-source community. Access the source code

Introduction

Welcome to Installation. This lab is a part of the Rust Book. You can practice your Rust skills in LabEx.

In this lab, you will need to install Rust using rustup, a command line tool for managing Rust versions and associated tools, by downloading it through an internet connection.

Installation

The first step is to install Rust. We'll download Rust through rustup, a command line tool for managing Rust versions and associated tools. You'll need an internet connection for the download.

Note: If you prefer not to use rustup for some reason, please see the Other Rust Installation Methods page at https://forge.rust-lang.org/infra/other-installation-methods.html for more options.

The following steps install the latest stable version of the Rust compiler. Rust's stability guarantees ensure that all the examples in the book that compile will continue to compile with newer Rust versions. The output might differ slightly between versions because Rust often improves error messages and warnings. In other words, any newer, stable version of Rust you install using these steps should work as expected with the content of this book.

Command Line Notation

In this chapter and throughout the book, we'll show some commands used in the terminal. Lines that you should enter in a terminal all start with $. You don't need to type the $ character; it's the command line prompt shown to indicate the start of each command. Lines that don't start with $ typically show the output of the previous command. Additionally, PowerShell-specific examples will use > rather than $.

Installing rustup on Linux or macOS

If you're using Linux or macOS, open a terminal and enter the following command:

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

The command downloads a script and starts the installation of the rustup tool, which installs the latest stable version of Rust. You might be prompted for your password. If the install is successful, the following line will appear:

Rust is installed now. Great!

You will also need a linker, which is a program that Rust uses to join its compiled outputs into one file. It is likely you already have one. If you get linker errors, you should install a C compiler, which will typically include a linker. A C compiler is also useful because some common Rust packages depend on C code and will need a C compiler.

Linux users should generally install GCC or Clang, according to their distribution's documentation. For example, if you use Ubuntu, you can install the build-essential package.

Troubleshooting

To check whether you have Rust installed correctly, open a new shell and enter this line:

## Open a new terminal first!
rustc --version

You should see the version number, commit hash, and commit date for the latest stable version that has been released, in the following format:

rustc x.y.z (abcabcabc yyyy-mm-dd)

If you see this information, you have installed Rust successfully! If you don't see this information, check that Rust is in your %PATH% system variable as follows.

in Linux, use:

echo $PATH

If that's all correct and Rust still isn't working, there are a number of places you can get help. Find out how to get in touch with other Rustaceans (a silly nickname we call ourselves) on the community page at https://www.rust-lang.org/community.

Updating and Uninstalling

Once Rust is installed via rustup, updating to a newly released version is easy. From your shell, run the following update script:

rustup update

To uninstall Rust and rustup, run the following uninstall script from your shell:

rustup self uninstall

Enter N when prompted to confirm that you want to uninstall Rust.

Local Documentation

The installation of Rust also includes a local copy of the documentation so that you can read it offline. Run rustup doc to open the local documentation in your browser.

rustup doc

Any time a type or function is provided by the standard library and you're not sure what it does or how to use it, use the application programming interface (API) documentation to find out!

Note: The WebIDE does not support opening local documentation.

Summary

Congratulations! You have completed the Installation lab. You can practice more labs in LabEx to improve your skills.

Other Tutorials you may like