Installing Rust
Installing Rust is straightforward thanks to Rustup, the official Rust installer and version manager. In this lesson, you'll learn how to install Rust on Windows, macOS, and Linux, set up your development environment, and verify everything is working correctly.
What is Rustup?
Rustup is the recommended way to install Rust. It's a toolchain installer that manages:
- Rust compiler (rustc): Compiles your Rust code
- Cargo: Rust's package manager and build tool
- Standard library: Core Rust functionality
- Toolchains: Different versions of Rust (stable, beta, nightly)
- Install and update Rust
- Switch between Rust versions
- Add cross-compilation targets
- Install additional components (rustfmt, clippy)
Installation Instructions
Windows
On Windows, you'll need the Microsoft C++ build tools before installing Rust.
- Install Visual Studio C++ Build Tools:
- Download from Microsoft's website
- Run the installer and select "Desktop development with C++"
- Download Rustup:
- Visit rustup.rs
- Download and run
rustup-init.exe
- Run the Installer:
- Follow the prompts (default options are recommended)
- The installer will add Rust to your PATH
macOS
On macOS, you'll need Xcode Command Line Tools.
- Install Xcode Command Line Tools:
xcode-select --install - Install Rustup:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh - Follow the Prompts:
- Press
1for default installation - The installer will configure your PATH automatically
- Press
- Reload your shell:
source $HOME/.cargo/env
Linux
On Linux, installation is similar to macOS.
- Install build essentials:
# Ubuntu/Debian sudo apt update sudo apt install build-essential # Fedora sudo dnf install gcc # Arch sudo pacman -S base-devel - Install Rustup:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh - Configure PATH:
source $HOME/.cargo/env
Verify Installation
After installation, verify that Rust is installed correctly:
# Check Rust compiler version
rustc --version
# Check Cargo version
cargo --version
# Check Rustup version
rustup --version
You should see output similar to:
rustc 1.75.0 (82e1608df 2023-12-21)
cargo 1.75.0 (1d8b05cdd 2023-11-20)
rustup 1.26.0 (5af9b9484 2023-04-05)
rustup update.
Rust releases a new stable version every 6 weeks with improvements and bug
fixes.
Essential Rustup Commands
Here are the most useful Rustup commands you'll need:
| Command | Description |
|---|---|
rustup update |
Update Rust to the latest version |
rustup self uninstall |
Uninstall Rust and Rustup |
rustup doc |
Open offline documentation |
rustup component add rustfmt |
Install code formatter |
rustup component add clippy |
Install linter for code quality |
rustup component add rustfmt clippy
Common Mistakes
1. PATH not updated
Problem: Commands like rustc or
cargo not found after installation
Solution: Restart your terminal or manually source the environment:
# macOS/Linux
source $HOME/.cargo/env
# Windows: Restart terminal or add to PATH manually
# %USERPROFILE%\.cargo\bin
2. Missing C++ build tools (Windows)
Problem: Compilation fails with linker errors
Solution: Install Visual Studio C++ Build Tools before Rust
3. Using outdated Rust version
Problem: Code examples don't work or new features unavailable
Solution: Update regularly with rustup update
Summary
- Rustup is the official Rust installer and version manager
- Installation requires C++ build tools on Windows, Xcode tools on macOS, and build-essential on Linux
- Verify installation with
rustc --versionandcargo --version - Keep Rust updated with
rustup update - Install rustfmt and clippy for better development experience
- Use
rustup docto access offline documentation
What's Next?
Now that Rust is installed, you're ready to write your first Rust program! In the next lesson, we'll create a "Hello, World!" program, understand the basic structure of a Rust program, and learn how to compile and run it.
Enjoying these tutorials?