Module 1 • Lesson 2

Installing Rust and Cargo

📚 6 min read 💻 Free Course 🦀 nixus.pro

Installing Rust: The Official Way

Rust is installed via rustup - the official toolchain manager. Unlike most languages, you do not download a platform installer. Rustup handles everything: the compiler, standard library, Cargo (the package manager), and keeps everything updated.

On Linux/macOS

Open your terminal and run:

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

This downloads and runs the rustup installer. Follow the prompts - the default installation is correct for most users. Press 1 to proceed with default installation.

After installation, add Rust to your PATH:

source ~/.cargo/env
# Or restart your terminal

On Windows

Download rustup-init.exe from rustup.rs and run it. On Windows, you also need the Visual C++ Build Tools - the installer will prompt you to install them.

Windows Tip

Use Windows Subsystem for Linux (WSL2) if you are doing serious systems work. The Linux development experience for Rust is smoother. That said, Rust on native Windows works perfectly fine.

Verifying Your Installation

After installation, verify everything works:

rustc --version
# rustc 1.76.0 (07dca489a 2024-02-04)

cargo --version
# cargo 1.76.0 (07dca489a 2024-02-04)

rustup --version
# rustup 1.26.0 (5af9b9484 2023-04-05)

If any of these fail, restart your terminal and try again. If still failing, re-run the rustup installer.

Updating Rust

Rust releases stable updates every 6 weeks. Keeping current is important:

rustup update
# Checks for updates and installs them automatically

Understanding Cargo: Your Best Friend

Cargo is Rust's build system and package manager. It does everything:

# Create a new project
cargo new hello_rust
cd hello_rust

# Structure created:
# hello_rust/
#   Cargo.toml    - Project manifest
#   src/
#     main.rs     - Your code

# Build and run
cargo run

# Just build
cargo build

# Build optimized release version
cargo build --release

# Check for errors without building
cargo check    # Faster than build, great for dev

# Run tests
cargo test

cargo check is your best friend during development - it validates your code without the overhead of full compilation. Use it constantly.

The Cargo.toml File

Every Rust project has a Cargo.toml (TOML = Tom's Obvious, Minimal Language). This is your project manifest:

[package]
name = "hello_rust"
version = "0.1.0"
edition = "2021"

[dependencies]
# Add libraries here, for example:
# serde = { version = "1", features = ["derive"] }
# tokio = { version = "1", features = ["full"] }

The edition = "2021" specifies which Rust edition to use. Always use 2021 for new projects - it is the current standard with the best ergonomics.

Adding Dependencies

# Add a dependency directly
cargo add serde

# Add with specific features
cargo add tokio --features full

# The Cargo.toml updates automatically!
# And cargo build downloads + compiles the dependency

Choosing Your Editor

Rust has excellent editor support. Here are the top choices:

EditorSetupExperience
VS CodeInstall "rust-analyzer" extensionBest for beginners. Full IntelliSense, debugging.
RustRoverJetBrains IDE, install from jetbrains.comMost powerful Rust-specific IDE. Free for non-commercial.
Neovimrust-analyzer LSP + nvim-cmpExcellent for experienced vim users
HelixBuilt-in LSP supportModern modal editor, great Rust support out of box

Install rust-analyzer no matter what editor you choose. It is the official Rust language server and provides real-time type information, autocompletion, and inline error messages. It is essentially a second pair of eyes reading your code as you type.

🎯 Setup Exercise

  1. Install Rust via rustup and verify with rustc --version
  2. Create a new project: cargo new my_first_rust && cd my_first_rust
  3. Open it in your editor and install rust-analyzer
  4. Run cargo run and see the "Hello, world!" output
  5. Run cargo check and note how much faster it is than cargo build

🎉 Key Takeaways