Beginner · Getting started with Rust · topic 2 of 50 · 20 min
Installing Rust with rustup
Explanation
Why an installer called rustup?
Rust releases a new stable version every six weeks. You do not want to download and reinstall by hand each time. rustup is a small program that installs Rust and keeps it up to date. It can also hold several versions side by side, called toolchains.
What gets installed
| Tool | What it does |
|---|---|
| rustup | Installs and updates Rust, and switches between toolchains |
| rustc | The compiler: turns .rs files into a program |
| cargo | The build tool and package manager: creates projects, builds, runs, tests and downloads libraries |
| std | The standard library: ready-made code for text, files, collections, threads and more |
| rustfmt and clippy | A code formatter and a linter (a tool that warns about bad patterns) |
Installing on Windows
- Open rustup.rs in your browser and download rustup-init.exe.
- Run it. If it says the Microsoft C++ build tools are missing, let it install them, or install "Build Tools for Visual Studio" with the "Desktop development with C++" option. Rust uses Microsoft's linker on Windows. A linker joins compiled pieces into one .exe file.
- Choose the default installation (option 1).
- Close and reopen your terminal so it can find the new commands.
Installing on macOS and Linux
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shCheck that it worked
rustc --version
cargo --version
rustup --versionPATH is the list of folders your terminal searches for commands. rustup adds the folder with cargo and rustc to it, but only new terminal windows see the change.
Toolchains and updates
- stable: the normal version for real work. Use this.
- beta: the next stable version, for testing.
- nightly: built every night, with experimental features. Some tools need it, but beginners do not.
rustup update
rustup toolchain list
rustup component add clippy rustfmtAn editor: VS Code and rust-analyzer
Install VS Code, then the extension named rust-analyzer (from the rust-lang publisher). It shows types as you type, underlines errors before you compile, completes code and jumps to definitions. It is the official language server for Rust. A language server is a background program that gives an editor smart features for one language.
Common mistakes
- Installing Rust from a random website or an old package manager version. Use rustup so updates are easy.
- On Windows, skipping the C++ build tools. You then see "linker link.exe not found". Install the build tools and try again.
- Running rustc in an old terminal window right after installing. Open a new one.
- Installing nightly "to get the newest". Stable is what tutorials and jobs expect.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Installing Rust with rustup · 1/7
Let us install Rust. The official way is a small tool called rustup.
Prefer a video by a teacher? Find free videos on “install rust rustup windows vs code rust-analyzer” on YouTube ↗
In real life: Setting up a new laptop at work
A new developer joins a fintech startup in Bengaluru. The team README says: "Install Rust with rustup, then run cargo build." Because everyone uses rustup and the same stable toolchain, the project builds the same way on her Windows laptop, a teammate's MacBook and the Linux build server. A rust-toolchain.toml file in the project can even pin the exact version so nobody gets surprises.
rustup update
rustc --version
cargo buildPractice (0/2 done)
You just installed Rust on Windows, but the terminal says cargo is not recognised. What should you try first?
Install Rust on your computer (or open the Rust Playground if you cannot install). Record the output of the version commands.
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Your first program and cargoGetting started with Rust · same module
- Variables, mutability, shadowing and constantsGetting started with Rust · same module
- Installing Go and the go commandGo Programming (backend and cloud) · Getting started with Go
- Installing .NET and using the dotnet CLIC# and .NET · Getting started with C# and .NET
- Installing FlutterFlutter and Dart · Flutter setup and your first app
- Tooling: rustfmt, Clippy, docs and editionsTesting, tooling and unsafe Rust
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
What is rustup?
Answer: The official installer and toolchain manager
rustup installs Rust, updates it and switches between toolchains.
Which toolchain should a beginner use?
Answer: stable
stable is tested and is what tutorials, books and employers expect.
On Windows you see "linker link.exe not found". What is missing?
Answer: The Microsoft C++ build tools
Rust on Windows (the default MSVC toolchain) uses Microsoft's linker from the C++ build tools.
What does rust-analyzer give you?
Answer: Smart editor features: errors, types and completion as you type
It is a language server that powers editor features for Rust.
Which tool finds suspicious code that still compiles, like a wrong Printf format?Related
Answer: go vet
go vet reports likely mistakes such as format strings that do not match their arguments.
Where does a cargo project keep its main code?Related
Answer: src/main.rs
cargo new puts the starting code in src/main.rs.
What do you need to install to BUILD C# programs?Related
Answer: The .NET SDK
The SDK has the compiler and the dotnet tools. The runtime alone can only run built apps.
What do you need to build an iOS app?Related
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 2 more topics in “Getting started with Rust” before its exam: Your first program and cargo, Variables, mutability, shadowing and constants.
- Module 1 exam: Getting started with Rust · 12 questions · 20 min, without help. 4 topics of this module still to finish first.
- Then the next module, Types, control flow and functions. 50 topics left in the course before the final exam.