Install Rust with rustup
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:
| Tool | What it does |
|---|---|
rustc | The Rust compiler |
cargo | Build tool and package manager (you will use this most) |
rustup | Installs, updates and switches toolchains |
rustfmt | Formats your code in the standard style (cargo fmt) |
clippy | A linter with hundreds of extra checks (cargo clippy) |
rust-docs | An 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
- Open the official install page at rust-lang.org/tools/install and download
rustup-init.exefor your processor (most laptops need the x64 build). - 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. - Choose the default installation when rustup asks.
- Close the terminal and open a new one so the updated
PATHis loaded.
If you prefer the command line, Windows Package Manager can install rustup too:
winget install Rustlang.RustupInstalling on Linux and macOS
Run this command in a terminal. It downloads the rustup installer over HTTPS and starts it:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shPress 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:
rustc --version
cargo --version
rustup --versionEach 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:
fn main() {
println!("Rust is installed on Ananya's laptop!");
}Compile it with rustc, then run the program it creates:
rustc main.rs
./mainRust 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:
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 completelyRust 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:
[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
PATHchange only applies to terminals opened after installation. - Missing linker. An error saying that the linker
link.exewas not found means the MSVC build tools are missing on Windows. On Linux the same error namescc, and you needbuild-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 --versiondoes not show an old version.
Key points
- rustup is the official installer and toolchain manager; it installs
rustc,cargo,rustfmt,clippyand offline docs. - Windows needs the MSVC build tools; Linux and macOS need a C linker.
- Check the install with
rustc --versionandcargo --versionin a new terminal. - Update with
rustup update; stable is the channel to use, andrust-toolchain.tomlpins 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
fn main() {
println!("Name: Kabir");
println!("City: Kochi");
}rustc hello.rs
./hello # on Windows: .\hello.exe
rustup doc --bookName: 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?
rustup is the toolchain manager; cargo builds projects and rustc compiles code.
2. What does Rust need on Windows besides rustup?
Rust uses Microsoft's linker on Windows, so the Visual Studio C++ build tools must be installed.
3. You installed Rust, but rustc --version says the command is not recognized. What is the most likely fix?
rustup updates the PATH, but only terminals started after the install see the change.
4. Which release channel should you use for normal work?
Stable is the tested, supported channel; nightly has unfinished features that can change.
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
