MeshWorld India LogoMeshWorld.
HowToRustCargoRustupLinuxProgramming5 min read

How to Install Rust and Cargo on Ubuntu, macOS, and Windows (2026)

Vishnu
By Vishnu
·
Vishnu
Updated by Vishnu
|Updated: Jul 24, 2026
How to Install Rust and Cargo on Ubuntu, macOS, and Windows (2026)

Rust is a modern systems programming language empowering developers to build fast, memory-safe, and concurrent software without relying on a garbage collector. Consistently voted among the most loved languages in global developer surveys, Rust powers operating system kernels, WebAssembly modules, CLI utilities, network proxies, and high-performance backend microservices.

Installing Rust using Rustup (the official Rust toolchain installer) provides access to rustc (the compiler), cargo (the package manager and build system), and clippy (the linter).

Whether setting up a development workstation on Ubuntu 24.04 LTS (Noble Numbat), 22.04 LTS, macOS, or Windows, here is the complete 2026 installation guide.

Last updated: July 24, 2026

Key Takeaways

  • Always install Rust via `rustup` rather than Linux distribution package managers (`apt`), as `rustup` manages official release channels (stable, beta, nightly).
  • A C compiler (such as `gcc` or `clang`) and build dependencies must be installed on your operating system to support linker operations.
  • Cargo is Rust's official package manager, build tool, and dependency resolver: handling compilation, testing, and documentation generation.
  • After running the Rustup installation script, refresh your terminal environment using `source '$HOME/.cargo/env'`.

What are the system prerequisites for installing Rust?

Before executing the Rust installation script, install the required C compiler and linker build tools for your platform:

On Ubuntu / Debian / Linux Mint

Open terminal (Ctrl+Alt+T) and install build-essential and development libraries:

bash
sudo apt update
sudo apt install -y build-essential gcc pkg-config libssl-dev curl

On macOS

Install Command Line Tools for Xcode via terminal:

bash
xcode-select --install

On Windows

Download and install the Visual Studio Community build tools with the Desktop development with C++ workload selected, or install WSL2 (Windows Subsystem for Linux).


How do you install Rust and Cargo via Rustup?

The official recommended installer for Rust across all operating systems is Rustup.

Step 1: Run the Official Rustup Installation Script

Execute the following secure HTTPS shell command in your terminal:

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

Step 2: Choose Installation Options

The installer displays a summary of target architecture and directory paths:

text
1) Proceed with standard installation (default - recommended)
2) Customize installation
3) Cancel installation

Type 1 and press Enter to complete the standard installation.

Step 3: Configure Environment Variables

Rustup installs binaries into $HOME/.cargo/bin. Source the environment configuration into your current terminal session:

bash
source "$HOME/.cargo/env"

To ensure cargo and rustc load automatically in future terminal windows, append the PATH entry to your shell configuration (~/.bashrc or ~/.zshrc):

bash
echo 'source "$HOME/.cargo/env"' >> ~/.bashrc

Step 4: Verify Installation

Confirm that the Rust compiler (rustc), package manager (cargo), and toolchain manager (rustup) are active:

bash
rustc --version
cargo --version
rustup --version

Expected output example: rustc 1.8x.x (hash date)


How do you manage Rust toolchains and updates?

rustup allows switching between release channels and target platforms without touching system files.

1. Updating Rust to the Latest Stable Version

Rust releases stable updates every 6 weeks. To update your compiler and tools:

bash
rustup update

2. Installing and Switching Toolchains (Nightly / Beta)

If a project requires experimental features or nightly compiler flags:

bash
# Install nightly toolchain
rustup toolchain install nightly

# Set default toolchain to nightly
rustup default nightly

# Switch back to stable toolchain
rustup default stable

3. Adding Cross-Compilation Targets (WebAssembly / Musl)

To compile statically linked binaries using musl or build WebAssembly modules:

bash
# Add musl target for static Linux binaries
rustup target add x86_64-unknown-linux-musl

# Add WebAssembly target
rustup target add wasm32-unknown-unknown

How do you create and run your first Rust project with Cargo?

Cargo streamlines creating, building, running, and testing Rust applications.

Step 1: Initialize a New Binary Project

Navigate to your workspace directory and create a project:

bash
cargo new hello_rust
cd hello_rust

This creates a standard project layout:

  • Cargo.toml: Manifest file containing metadata and crate dependencies.
  • src/main.rs: Source file containing the entry point fn main().

Step 2: Review project code

Inspect src/main.rs:

rust
fn main() {
    println!("Hello, World!");
}

Step 3: Compile and Execute with Cargo

Build and run your application in development mode:

bash
cargo run

Output:

text
   Compiling hello_rust v0.1.0 (/path/to/hello_rust)
    Finished dev [unoptimized + debuginfo] target(s) in 0.42s
     Running `target/debug/hello_rust`
Hello, World!

Step 4: Build a Production Release Binary

When deploying to production, compile with optimizations enabled:

bash
cargo build --release

The optimized executable will be located in target/release/hello_rust.


Pro Tip: Fast Code Checking with Cargo Check

During active development, run cargo check instead of cargo build. cargo check verifies syntax and type correctness without generating machine code binaries: running 2x to 5x faster.


Frequently Asked Questions (PAA)

Why shouldn’t I install Rust using sudo apt install rustc?

Linux distribution repositories package specific, static Rust versions that lag behind current compiler releases. Installing via rustup ensures you get the latest stable tools and can update seamlessly.

Is Cargo included when installing Rust via Rustup?

Yes. Rustup automatically installs rustc (the compiler), cargo (the package manager), rust-std (the standard library), and rust-docs (local documentation).

How do I uninstall Rust completely?

To remove Rustup, Cargo, and all installed toolchains from your computer, run:

bash
rustup self uninstall

Where are Cargo dependencies (crates) stored locally?

Cargo caches downloaded dependencies from Crates.io inside $HOME/.cargo/registry/ and $HOME/.cargo/git/.


Share_This Twitter / X
Vishnu
Written By

Vishnu

Founder & Principal Architect at MeshWorld. Senior engineer and instructor specializing in AI agent systems, scalable web architecture, and modern development workflows.

Vishnu
Updated By

Vishnu

Founder & Principal Architect at MeshWorld. Senior engineer and instructor specializing in AI agent systems, scalable web architecture, and modern development workflows.

Enjoyed this article?

Support MeshWorld and help us create more technical content