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 | shThis 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 terminalOn 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.
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 automaticallyUnderstanding Cargo: Your Best Friend
Cargo is Rust's build system and package manager. It does everything:
- Creates new projects with proper structure
- Builds your code (
cargo build) - Runs your code (
cargo run) - Tests your code (
cargo test) - Downloads and manages dependencies
- Publishes packages to crates.io
# 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 testcargo 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 dependencyChoosing Your Editor
Rust has excellent editor support. Here are the top choices:
| Editor | Setup | Experience |
|---|---|---|
| VS Code | Install "rust-analyzer" extension | Best for beginners. Full IntelliSense, debugging. |
| RustRover | JetBrains IDE, install from jetbrains.com | Most powerful Rust-specific IDE. Free for non-commercial. |
| Neovim | rust-analyzer LSP + nvim-cmp | Excellent for experienced vim users |
| Helix | Built-in LSP support | Modern 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
- Install Rust via rustup and verify with
rustc --version - Create a new project:
cargo new my_first_rust && cd my_first_rust - Open it in your editor and install rust-analyzer
- Run
cargo runand see the "Hello, world!" output - Run
cargo checkand note how much faster it is thancargo build
🎉 Key Takeaways
- Install Rust via rustup - it manages compiler versions, components, and updates
- Cargo is the build tool, package manager, and test runner all in one
- Use
cargo checkconstantly during development for fast feedback - Install rust-analyzer in your editor - it is non-negotiable
- Cargo.toml is your project manifest - all dependencies go here