Skip to main content

Install Rust

Installation

The first step in using Rust is to install it. We will download Rust through rustup, a command-line tool for managing Rust versions and associated tools. An internet connection is required for download.

Note: If for some reason you prefer not to use rustup, please see the Other Installation Methods page for Rust for more installation options.

The steps below will install the latest stable version of the Rust compiler. Different versions may vary slightly, as Rust often improves error messages and warnings. Nevertheless, any of the newest stable versions of Rust installed by these steps should be able to run all the content in this book.

Command Line Notation

Throughout this book, and this chapter in particular, we will display some commands used in the terminal. All lines that you should enter into your terminal begin with $. You do not need to type the $ character; it is there to denote the start of each command. Lines not starting with $ typically show the output of the previous command. Additionally, PowerShell-specific examples will use > instead of $.

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.2 -sSf https://sh.rustup.rs | sh

This command will download a script and start the installation of the rustup tool, which installs the latest stable version of Rust. During the process, you may be prompted for your password. If the installation is successful, you will see the following message:

Rust is installed now. Great!

Additionally, you'll need a linker, which is a program that Rust uses to link its compiled output into a file. It's likely you already have one. If you receive linker errors, try installing a C compiler, which usually includes a linker. A C compiler will also be useful because some common Rust packages depend on C code, hence the need for a C compiler.

On macOS, you can get a C compiler by running the following command:

$ xcode-select --install

Linux users typically need to install GCC or Clang according to their distribution's documentation. For instance, if you are using Ubuntu, you can install the build-essential package.

Installing rustup on Windows

On Windows, go to install and follow the instructions to install Rust. At some point in the installation, you'll receive a message explaining the necessity for installing the MSVC build tools for Visual Studio 2013 or later.

To get the build tools, you need to install Visual Studio 2022. When asked about what workloads to install, make sure the following are checked:

  • "Desktop Development with C++"
  • Windows 10 (or 11) SDK
  • The English language pack, and any other language packs you require

The remainder of this book will use commands that should work in both cmd.exe and PowerShell. If there are specific differences, we will explain which to use.

Troubleshooting

To check if Rust was installed correctly, open a command line and enter:

$ rustc --version

You should be able to see the version number, commit hash, and commit date for the latest stable version in the following format:

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

If you see this information, Rust is successfully installed!

If you don't, check if Rust is in your %PATH% system variable.

On Windows CMD, use:

> echo %PATH%

On PowerShell, use:

> echo $env:Path

On Linux and macOS, use:

$ echo $PATH

If everything seems correct but Rust is still not working, there are many places to get help. You can see how to get in touch with other Rustaceans on the community page.

Updating and Uninstalling

Once you have installed Rust via rustup, updating to the latest version is simple; just run the following update script in your corresponding command line:

$ rustup update

To uninstall Rust and rustup, run the following uninstall script in the command line:

$ rustup self uninstall

Local Documentation

The installation also includes a local copy of the documentation, which you can read offline. Run rustup doc to open the local documentation in your browser.

Anytime you are uncertain about the use and behavior of types or functions in the standard library, check the API documentation!

References