Install Rust with rustup

Rust · Lesson 2 of 31 8 min read Updated

Before you can write Rust you need the Rust toolchain: the compiler, the Cargo build tool and the standard library. The official way to install and manage all of them is a small program called rustup.

In this lesson you will install Rust on your operating system, check that it works, learn the rustup commands you will use every month, and set up an editor that understands Rust.

What rustup installs

rustup is a toolchain manager. It downloads Rust from the official servers, keeps it up to date, and can hold several versions side by side. One install gives you:

ToolWhat it does
rustcThe Rust compiler
cargoBuild tool and package manager (you will use this most)
rustupInstalls, updates and switches toolchains
rustfmtFormats your code in the standard style (cargo fmt)
clippyA linter with hundreds of extra checks (cargo clippy)
rust-docsAn offline copy of the official documentation

All these programs are placed in a folder called .cargo/bin inside your home folder (%USERPROFILE%\.cargo\bin on Windows), and rustup adds that folder to your PATH.

Installing on Windows

  1. Open the official install page at rust-lang.org/tools/install and download rustup-init.exe for your processor (most laptops need the x64 build).
  2. Run it. Rust on Windows needs the MSVC build tools from Microsoft, which provide the linker that joins compiled code into an .exe. If they are missing, the installer offers to install them through the Visual Studio installer. Accept, and tick the "Desktop development with C++" workload if you are asked.
  3. Choose the default installation when rustup asks.
  4. Close the terminal and open a new one so the updated PATH is loaded.

If you prefer the command line, Windows Package Manager can install rustup too:

PowerShell
winget install Rustlang.Rustup

Installing on Linux and macOS

Run this command in a terminal. It downloads the rustup installer over HTTPS and starts it:

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

Press Enter to accept the default installation. Then either open a new terminal or load the new PATH into the current one with . "$HOME/.cargo/env".

Rust also needs a C linker on these systems. On Ubuntu or Debian install it with sudo apt install build-essential; on macOS run xcode-select --install.

Check that it works

Open a fresh terminal and ask each tool for its version:

Terminal
rustc --version
cargo --version
rustup --version

Each command prints a line starting with the tool name and its version, for example rustc 1.99.1 followed by a commit hash and a build date in brackets. If you see "command not found" or "is not recognized", the terminal has not picked up the new PATH yet: close it and open a new one, or log out and in again.

Compile a file by hand

You will normally use Cargo, but it is useful to see the compiler on its own once. Create a file called main.rs:

Rust
fn main() {
    println!("Rust is installed on Ananya's laptop!");
}

Compile it with rustc, then run the program it creates:

Terminal
rustc main.rs
./main
Output
Rust is installed on Ananya's laptop!

On Windows the program is main.exe, so run it with .\main.exe. The compiler also creates a main.pdb file there, which holds debugging information.

Everyday rustup commands

Rust releases a new stable version every six weeks, so you will update regularly. These are the commands you will actually use:

Terminal
rustup update                      # update every installed toolchain
rustup show                        # list toolchains and the active one
rustup component add rustfmt clippy
rustup toolchain install nightly   # optional: the nightly channel
rustup doc --book                  # open the Rust Book offline in your browser
rustup self uninstall              # remove Rust completely

Rust has three release channels. Stable is what you should use. Beta is the next stable version under testing. Nightly is built every night and contains unfinished features; some experimental crates need it, but this course never does.

A project can pin the exact toolchain it needs with a rust-toolchain.toml file in its root folder. Everyone who builds the project, including a CI server, then gets the same version automatically:

TOML
[toolchain]
channel = "1.99.0"
components = ["rustfmt", "clippy"]

Choose an editor

  • VS Code with the rust-analyzer extension is the most common setup. rust-analyzer shows types as you type, highlights errors before you compile, offers auto-completion and can run a single test with one click.
  • RustRover from JetBrains is a full Rust IDE, free for non-commercial use such as learning.
  • Zed, Neovim and Helix also work well with rust-analyzer.

Install only the rust-analyzer extension for Rust; older guides recommend an extension simply called "Rust", which is no longer maintained.

Common mistakes

  • Not restarting the terminal. The PATH change only applies to terminals opened after installation.
  • Missing linker. An error saying that the linker link.exe was not found means the MSVC build tools are missing on Windows. On Linux the same error names cc, and you need build-essential (or your distribution's equivalent).
  • Installing with sudo. rustup installs into your own home folder. Run it as your normal user, not as root.
  • Mixing two installations. If you installed Rust from a package manager earlier, remove it first so rustc --version does not show an old version.

Key points

  • rustup is the official installer and toolchain manager; it installs rustc, cargo, rustfmt, clippy and offline docs.
  • Windows needs the MSVC build tools; Linux and macOS need a C linker.
  • Check the install with rustc --version and cargo --version in a new terminal.
  • Update with rustup update; stable is the channel to use, and rust-toolchain.toml pins a version per project.
  • VS Code with rust-analyzer, or RustRover, gives you live errors and completion.

Exercise

Install Rust on your computer. Then create a file hello.rs that prints your name and your city on two lines, compile it with rustc, and run it. Finally, run the command that opens the Rust Book offline.

Show solution
Rust
fn main() {
    println!("Name: Kabir");
    println!("City: Kochi");
}
Terminal
rustc hello.rs
./hello            # on Windows: .\hello.exe
rustup doc --book
Output
Name: Kabir
City: Kochi

rustc creates a program named after the source file, and rustup doc --book opens the locally installed copy of the book, so it works without internet.

Quick Quiz

1. Which tool installs Rust and keeps it up to date?

2. What does Rust need on Windows besides rustup?

3. You installed Rust, but rustc --version says the command is not recognized. What is the most likely fix?

4. Which release channel should you use for normal work?

Learn Rust with a mentor

Free lessons get you started. Our Programming & Software Development training adds real projects and code reviews from working developers.

  • Project-based learning
  • Mentor code reviews
  • Free counselling call