Skip to content

Rust Installation Guide — Set Up Rust with rustup cargo and rustc

DodaTech Updated 2026-06-28 5 min read

In this tutorial, you will learn about Rust Installation Guide. We cover key concepts, practical examples, and best practices to help you master this topic.

Install Rust using rustup for toolchain management across channels (stable, beta, nightly), cargo for package management, builds, and testing, and rustc for direct compilation.

What You'll Learn

  • Installing Rust with rustup
  • Using cargo for project management
  • Compiling with rustc
  • Setting up your development environment

Why It Matters

A proper Rust setup is essential. Firefox uses specific Rust toolchains for building. Cloudflare Workers uses rustup for cross-compilation. Doda Browser uses cargo for dependency management. The toolchain is modern and comprehensive.

Real-World Use

Every Rust project uses cargo for builds, testing, and dependency management. rustup manages multiple Rust versions. Cross-compilation targets are installed via rustup.

flowchart LR
    A["Install Rust"] --> B["rustup"]
    B --> C["cargo"]
    C --> D["rustc"]
    D --> E["Hello World"]
    A:::current --> B
    style A fill:#2563eb,stroke:#2563eb,color:#fff
    style B fill:#dbeafe,stroke:#2563eb,color:#1e40af
    style C fill:#dbeafe,stroke:#2563eb,color:#1e40af
    style D fill:#dbeafe,stroke:#2563eb,color:#1e40af
    style E fill:#f1f5f9,stroke:#94a3b8,color:#64748b

Installing with rustup

# Install rustup (Linux/macOS)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Follow the prompts — default installation is recommended

After installation, restart your shell or run:

source $HOME/.cargo/env

Windows

Download rustup-init.exe from rustup.rs and run it.

Verifying Installation

rustc --version
# rustc 1.80.0 (2026-06-15)

cargo --version
# cargo 1.80.0 (2026-06-15)

rustup --version
# rustup 1.27.0 (2025-02-10)

Your First Rust Program

fn main() {
    println!("Hello, Rust!");
    println!("Rust version: {}", env!("CARGO_PKG_RUSTC_VERSION"));
}

Using rustc Directly

echo 'fn main() { println!("Hello, world!"); }' > hello.rs
rustc hello.rs
./hello
# Hello, world!
cargo new hello_cargo
cd hello_cargo
cargo run
#    Compiling hello_cargo v0.1.0
#     Finished dev [unoptimized + debuginfo]
# Running `target/debug/hello_cargo`
# Hello, world!

Cargo Project Structure

my_project/
├── Cargo.toml     # Project metadata and dependencies
├── Cargo.lock     # Dependency lockfile
└── src/
    └── main.rs    # Source code

Cargo.toml

[package]
name = "my_project"
version = "0.1.0"
edition = "2024"

[dependencies]
serde = { version = "1.0", features = ["derive"] }

Common Cargo Commands

cargo new <name>      # Create new project
cargo build           # Build (debug)
cargo build --release # Build (release, optimized)
cargo run             # Build and run
cargo check           # Check code (no binary)
cargo test            # Run tests
cargo doc --open      # Build and open docs
cargo fmt             # Format code
cargo clippy          # Lint code
cargo add <crate>     # Add dependency

Managing Toolchains

# Install nightly
rustup install nightly

# Set default
rustup default stable
rustup default nightly

# Use nightly for specific project
cd my_project
rustup override set nightly

# Update all toolchains
rustup update

Cross-Compilation

# List available targets
rustup target list

# Install a target
rustup target add aarch64-unknown-linux-gnu

# Build for target
cargo build --target aarch64-unknown-linux-gnu

Development Tools

rustfmt

cargo fmt  # Format all Rust files

clippy

cargo clippy  # Lint for common mistakes

rust-analyzer

Install the rust-analyzer extension in VSCode for IDE support: code completion, go-to-definition, inline type hints.

Common Mistakes

1. Not Sourcing cargo Env

# After rustup install
source $HOME/.cargo/env  # Or restart shell

2. Forgetting cargo run vs cargo build

cargo run builds and runs. cargo build only builds. Use cargo build --release for optimized builds.

3. Not Understanding Release Mode

Debug builds are slow but have good error messages. Release builds are optimized but compile slower.

4. Using Wrong Edition

Rust 2024 edition is current. Set it in Cargo.toml.

5. Ignoring Compiler Warnings

Rust's compiler warnings often indicate real issues. Use #[allow(...)] sparingly.

Practice Questions

1. What does rustup manage? Rust toolchains (stable, beta, nightly) and cross-compilation targets.

2. What's the difference between cargo build and cargo check? cargo build produces a binary. cargo check only checks code for errors without producing a binary — faster for development iteration.

3. What is Cargo.toml? The project manifest file containing metadata (name, version, edition) and dependencies.

4. How do you add a dependency? Add it to [dependencies] in Cargo.toml or use cargo add <crate>.

Challenge: Create a new cargo project, add the serde and serde_json dependencies, and verify it builds.

Solution
cargo new demo_project
cd demo_project
cargo add serde --features derive
cargo add serde_json
cargo build

FAQ

{{< faq question="Should I use stable or nightly Rust?" >}} Use stable for production. Use nightly when you need unstable features or when contributing to projects that require nightly. {{< /faq >}}

{{< faq question="What is the difference between rustc and cargo?" >}} rustc is the Rust compiler. cargo is the build system and package manager that wraps rustc. Use cargo for almost everything. {{< /faq >}}

{{< faq question="How do I update Rust?" >}} rustup update updates all installed toolchains to the latest versions. {{< /faq >}}

{{< faq question="Can I have multiple Rust versions installed?" >}} Yes. rustup manages multiple toolchains. Use rustup install <toolchain> and rustup default <toolchain> to switch. {{< /faq >}}

{{< faq question="What code editor should I use for Rust?" >}} VSCode with rust-analyzer is the most popular choice. JetBrains RustRover is also excellent. Both provide IDE-level support. {{< /faq >}}

Try It Yourself

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

# Create and run a new project
cargo new my_first_project
cd my_first_project
cargo run

What's Next

Now that Rust is installed, learn about variables and mutability.

Topic Description Link
Rust Variables let, mut, constants, shadowing {{< ref "03-variables" >}}
Rust Control Flow if/else, loop, while, for, match {{< ref "04-control-flow" >}}
Go Installation Compare Go setup Go

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro