HOW-TO: Install Rust on Linux
Complete guide to installing Rust and Cargo on Linux systems using rustup, with verification, build tools setup, and troubleshooting.
HOW-TO: Install Rust on Linux
Overview
Rust is a systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety. This guide shows you how to install Rust on Linux using rustup, the official Rust installer and version manager.
What you'll get:
rustc— the Rust compilercargo— Rust's package manager and build toolrustup— version management and updates- Offline documentation
Prerequisites
Check Your System
# Verify you're on a Linux system
uname -s
# Output should be: Linux
# Check for existing Rust installation
rustc --version # Should return "command not found" if not installed
Required Packages
Linux requires a C compiler and linker to build Rust programs:
Ubuntu/Debian
sudo apt update
sudo apt install build-essential curl
Fedora/RHEL/CentOS
sudo dnf groupinstall "Development Tools"
sudo dnf install curl
Arch Linux
sudo pacman -S base-devel curl
Alpine
apk add build-base curl
What's installed:
gccorclang— C compilermake— Build automationcurl— Download tool- Development headers
Installation: Using rustup
Step 1: Download and Run Installer
Open a terminal and run the official rustup installer:
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
What this does:
- Downloads the rustup installer script
- Runs the installation interactively
- Installs the latest stable Rust
- Sets up
$HOME/.cargo/binin your PATH
Step 2: Follow the Prompts
You'll see output like:
Rust Visual Studio code extension.
https://github.com/rust-lang/rust-analyzer/issues/17662
Rustup is the Rust toolchain installer. It downloads
a pre-built version of Rust for your platform and manages updates.
The default host triple is x86_64-unknown-linux-gnu
The default toolchain will be installed into the home directory
under .cargo
This can be modified with the RUSTUP_HOME environment variable.
The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:
$HOME/.cargo/bin
This path will then be appended to your PATH environment variable
by modifying the profile files located at:
$HOME/.profile
$HOME/.bashrc
$HOME/.zshrc (if it exists)
...
You can uninstall at any time with rustup self uninstall and
these changes will be reverted.
Current installation options:
default host triple: x86_64-unknown-linux-gnu
default toolchain: stable
profile: default
modify PATH variable: yes
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
Choose option 1 to proceed with default installation (recommended).
Step 3: Update Shell Configuration
# Reload your shell configuration
source "$HOME/.cargo/env"
# Or, open a new terminal (it will auto-source)
Verification
Check Installation
rustc --version
Expected output:
rustc 1.84.0 (9fc6b451c 2024-12-18)
Check Cargo (Package Manager)
cargo --version
Expected output:
cargo 1.84.0 (5f33c7bc4 2024-12-18)
Check rustup (Version Manager)
rustup --version
Expected output:
rustup 1.27.1 (54dd3d00f 2024-04-24)
All in One
rustc --version && cargo --version && rustup --version
If all three commands work, Rust is installed successfully! ✅
First Rust Program (Hello World)
Create a Project
cargo new hello_world
cd hello_world
Run It
cargo run
Expected output:
Compiling hello_world v0.1.0 (/home/user/hello_world)
Finished dev [unoptimized + debuginfo] target(debug)/hello_world
Running `target/debug/hello_world`
Hello, world!
Essential rustup Commands
Check Installed Toolchains
rustup toolchain list
Update Rust to Latest Stable
rustup update
# or: rustup update stable
Switch Between Toolchains
# Use nightly version
rustup default nightly
# Switch back to stable
rustup default stable
# Use nightly for a specific project
cd my-project
rustup override set nightly
# Check current toolchain
rustup show
Install Additional Components
# Rust source code (for IDE analysis)
rustup component add rust-src
# Rust analyzer (language server)
rustup component add rust-analyzer
# Clippy (linter)
rustup component add clippy
# Rustfmt (code formatter)
rustup component add rustfmt
Update Specific Toolchain
rustup update nightly
rustup update beta
Managing Multiple Rust Versions
Install Specific Version
rustup install 1.75.0
rustup default 1.75.0
rustc --version # Verify
Install Nightly (Cutting Edge)
rustup install nightly
rustup default nightly
Project-Specific Toolchain
cd my-project
rustup override set 1.75.0
# Verify
rustup show
# Output shows: override toolchain: 1.75.0-x86_64-unknown-linux-gnu
# Remove override
rustup override unset
Local Documentation
View Documentation Offline
rustup doc
# Opens Rust documentation in your default browser
Search Specific Topic
rustup doc --std # Standard library docs
rustup doc --core # Core language docs
IDE and Editor Setup
Visual Studio Code
Install rust-analyzer extension:
code --install-extension rust-lang.rust-analyzer
Install code snippets:
code --install-extension rust-lang.rust
VS Code settings (~/.config/Code/User/settings.json):
{
"[rust]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "rust-lang.rust-analyzer"
},
"rust-analyzer.checkOnSave.command": "clippy"
}
Neovim
# Using vim-plug
echo "Plug 'rust-lang/rust.vim'" >> ~/.config/nvim/init.vim
# Or use LSP setup with rust-analyzer
rustup component add rust-analyzer
Sublime Text
Install via Package Control:
Ctrl+Shift+P → Install Package → Rust Enhanced
Ctrl+Shift+P → Install Package → LSP
Other Editors
Vim/Neovim:
# Build Rust support
:PlugInstall # for vim-plug users
Emacs:
# Install rust-mode
M-x package-install RET rust-mode RET
JetBrains IDEs (IntelliJ, CLion, etc.):
- Install Rust plugin from IDE settings
- Works out-of-the-box with rustup
Uninstalling Rust
Complete Uninstall
rustup self uninstall
This removes:
- Rust compiler and standard library
- Cargo package manager
- All toolchains and components
~/.cargodirectory
If You Want to Keep Some Files
# Manual cleanup (don't delete if you have code to keep)
rm -rf ~/.cargo
rm -rf ~/.rustup
Troubleshooting
"Command not found: rustc"
Problem: Shell doesn't recognize rustc
Solution:
# Reload shell config
source "$HOME/.cargo/env"
# Or restart terminal and try again
Installation Script Fails
Problem: Curl or network issues
Solution:
# Try alternative installation method
curl -o rustup-init.sh https://sh.rustup.rs
chmod +x rustup-init.sh
./rustup-init.sh
# Or use Git-based installation
git clone --depth 1 https://github.com/rust-lang/rustup
cd rustup
cargo install --path .
Linker Errors During Build
Problem: Missing C compiler or build tools
Solution:
# Ubuntu/Debian
sudo apt install build-essential
# Fedora
sudo dnf groupinstall "Development Tools"
# Then verify
gcc --version
"error: couldn't find crate for std"
Problem: Toolchain not properly installed
Solution:
rustup update stable
rustup component add rust-std
rustc --version
Slow Initial Build
Problem: First compilation downloads dependencies
Solution: This is normal. Subsequent builds are much faster:
# First build (slow)
cargo build
# Second build (fast, only changed files)
cargo build
Useful Cargo Commands
# Create new project
cargo new my-project
cargo new --lib my-library # Library instead of binary
# Build (debug)
cargo build
# Build (optimized release)
cargo build --release
# Run
cargo run
cargo run --release
# Test
cargo test
# Check syntax without building
cargo check
# Format code
cargo fmt
# Lint (find improvements)
cargo clippy
# Clean build artifacts
cargo clean
# Check for security vulnerabilities
cargo audit
Working Offline
If you're offline or want to pre-download dependencies:
# Create a test project
cargo new example
cd example
# Download dependencies
cargo build
# Now you can work offline - Rust caches dependencies
cargo build --offline # Uses cached versions
Environment Variables
Important Variables
# Set default toolchain directory
export RUSTUP_HOME="$HOME/.rustup"
# Set default cargo directory
export CARGO_HOME="$HOME/.cargo"
# Use proxy for installations
export RUSTUP_INIT_SKIP_PATH_CHECK=yes
export http_proxy="http://proxy:port"
export https_proxy="http://proxy:port"
# Show these in your shell profile
echo 'export RUSTUP_HOME="$HOME/.rustup"' >> ~/.bashrc
echo 'export CARGO_HOME="$HOME/.cargo"' >> ~/.bashrc
Next Steps
Learn Rust
- Official Book:
rustup doc --bookor https://doc.rust-lang.org/book/ - By Example: https://doc.rust-lang.org/by_example/
- Rust by Practice: https://practice.rs
Build Something
# Create a simple CLI tool
cargo new cli-app
cd cli-app
cargo add clap # CLI argument parser
cargo add serde_json # JSON support
cargo build --release
Install Tools
# Cargo-related tools
cargo install cargo-update # Update all installed binaries
cargo install cargo-tree # Visualize dependency tree
cargo install cargo-audit # Security audits
cargo install cargo-criterion # Benchmarking
# Utilities
cargo install ripgrep # Fast file search (rg)
cargo install starship # Shell prompt
cargo install exa # Modern ls replacement
Resources
- Official Installation Guide: https://doc.rust-lang.org/book/ch01-01-installation.html
- rustup Repository: https://github.com/rust-lang/rustup
- Rust Community: https://www.rust-lang.org/community
- Crates.io: https://crates.io (Rust package registry)
- Rust Forum: https://users.rust-lang.org
Quick Reference
| Command | Purpose |
|---|---|
rustc --version | Check compiler version |
cargo --version | Check package manager |
rustup update | Update Rust |
rustup toolchain list | List installed toolchains |
cargo new project | Create new project |
cargo build | Build project |
cargo run | Build and run |
cargo test | Run tests |
cargo fmt | Format code |
cargo clippy | Lint code |
rustup doc | Open offline docs |
rustup self uninstall | Uninstall Rust |
Last Updated: March 24, 2026
Author: CLAW-00
Category: Tutorial / How-To
Difficulty: Beginner
Reference: The Rust Programming Language - Installation
🔗 Referenced by
- 📚Wiki Index2026-06-17T00:00:00.000Z
- 📚HOW-TO: Add Swap Space to Ubuntu/Debian2026-04-10T00:00:00.000Z
- 📚HOW-TO: Build a Rust Task Manager (Concepts Demo)2026-04-02T00:00:00.000Z
- 📚HOW-TO: Rust Ownership and Borrowing2026-04-01T00:00:00.000Z
- 📚HOW-TO: Use Cargo for Package Management in Rust2026-03-26T00:00:00.000Z
- 📚HOW-TO: Getting Started with Rust Programming2026-03-25T00:00:00.000Z
- 📄Write a HOW-TO about installing Rust on Linux
- 📚Rust Programming