Rust installation

Rust requires that you install a toolchain on your computer. The toolchain includes the Rust compiler and various tools to make working with the language easier. The easiest way to install the toolchain is to visit the rustup website. rustup detects the operating system you’re running and displays instructions for your platform. Launch a web browser and open rustup.rs.

Installation on Microsoft Windows

If you’re a Microsoft Windows user, download and run the linked rustup-init.exe file. rustup might ask you to install the C++ build tools before proceeding. Microsoft Windows doesn’t ship with development tools, and the Windows platforms tools aren’t open source, so rustup can’t legally give them to you. If you see this message:

  1. Go to the “Visual Studio” download page.

  2. In the “Tools for Visual Studio 2019” section, download “Build Tools for Visual Studio 2019” and run the installer.

  3. Follow the on-screen instructions, and install the C++ build tools.

Installation on other operating systems

If you’re using a UNIX-derived operating system such as Mac OS X or Linux, rustup presents you with a command line and a “copy” button. Copy the command to your clipboard, open your terminal program, and paste the command into your terminal. Press “Enter” and the install will begin.

Finishing installations

The rustup installer is verbose, but will guide us on what to do next:

Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

*Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

  C:\Users\herbe\.rustup

This can be modified with the RUSTUP_HOME environment variable.
The Cargo home directory is located at:

  C:\Users\herbe\.cargo

This can be modified with the CARGO_HOME environment variable.

The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:

  C:\Users\herbe\.cargo\bin

This path will then be added to your PATH environment variable by
modifying the HKEY_CURRENT_USER/Environment/PATH registry key.

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

We’re then presented with installation options:

   default host triple: x86_64-pc-windows-msvc 
    default toolchain: stable (default)
             profile: default
 modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation

In most cases, we can type 1, followed by ENTER. If we need to change where Rust is installed, select option 2 and follow the on-screen instructions.

Note: You don’t need administrative privileges to install Rust inside your account.

Once you proceed with the installation, rustup will download several Rust packages and install them on your computer. Rustup adjusts your path, so it’s a good idea to restart your terminal if you want to keep using it.

Congratulations, Rust is installed and ready to use!

Verifying Rust installation

When we finish the installation process, open a new terminal/command prompt. At the command prompt, type rustup -V:

The version numbers, git build hashes, and dates will vary. If you see the package installed, then the installation was successful.

Now that you know Rust works on your computer, let’s prove it by running “Hello, World!”

Testing Rust with “Hello ,World!”

Rust can build a program that prints “Hello, World!” with a simple command. We’ll learn about the details of the program in Creating Your First Rust Program. For now, whet your appetite and test that Rust works on your computer:

  1. Create a new directory in which to place Rust projects.

  2. Open a command prompt or terminal.

  3. Navigate to the Rust project directory we created with cd, “cd Rust,” for example.

  4. Type cargo new testrust and “ENTER”.

  5. Change to the new testrust directory by typing “cd testrust” and “ENTER”.

  6. Run the new program by typing cargo run and “ENTER”. Observe the following:

➾ cargo run

  ❮   Compiling hello v0.1.0*
    Finished dev [unoptimized + debuginfo] target(s) in 0.85s
     Running `C:\Pragmatic\Book\code\target\debug\hello.exe`
Hello, world!

Now that we have a working Rust toolchain, we need to know how to keep it updated.

Updating Rust

Rust releases minor updates every six weeks. Minor releases include bug fixes and enhancements that won’t break our code. Major Rust releases occur every two to three years and may make large scale changes to the Rust language. The Rust developers are very careful to maintain compatibility.

If something changes substantially, deprecation warnings will start to appear when we compile our code, long before the feature is removed.

We can check if a new release is available at any time using rustup check.

The displayed versions will vary, and there may not be any updates available. If new versions are available, we can install them by typing rustup update in the command prompt or terminal.

Congratulations, Rust is installed and working, and we now know how to keep it up to date.

In the next lesson, we’ll set up the development environment.

Get hands-on with 1400+ tech skills courses.