How to Install Rust on Linux

Rust is a modern systems programming language that offers memory safety, speed, and concurrency. If you’re using Linux and want to get Rust installed, this guide will walk you through the recommended installation process using rustup, the official Rust toolchain installer.

System Requirements

Before we begin, make sure you have:

  • Linux Distribution: Any modern Linux distribution (Ubuntu, Fedora, Debian, Arch, etc.)
  • Architecture: Compatible with x86_64, ARM64, and other supported architectures
  • Internet connection: To download the installer and toolchain
  • Basic development tools: C compiler and linker (usually pre-installed or easily available)

Step 1: Install Prerequisites

Most Linux distributions need a C compiler and linker for Rust to work properly. Install the essential build tools:

For Ubuntu/Debian:

sudo apt update
sudo apt install build-essential

For Fedora:

sudo dnf groupinstall "Development Tools"

For Arch Linux:

sudo pacman -S base-devel

For openSUSE:

sudo zypper install -t pattern devel_basis

Step 2: Download and Install Rustup

Run the official rustup installer:

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

What this command does:

  • Downloads the rustup installer securely using HTTPS
  • Runs the installation script
  • Installs the latest stable Rust toolchain by default

Step 3: Follow the Installation Prompts

The installer will present you with options:

  1. Default installation (recommended): Press 1 or Enter
  2. Customize installation: Press 2 to modify installation options
  3. Cancel installation: Press 3 to exit

For most users, the default installation is perfect and will:

  • Install the stable Rust toolchain
  • Add Rust tools to your PATH
  • Install rustc (compiler), cargo (package manager), and other essential tools

Step 4: Configure Your Shell

After installation, you need to configure your shell environment. The installer will show you a command to run:

source $HOME/.cargo/env

Alternatively, restart your terminal or log out and back in for the changes to take effect.

Step 5: Verify Installation

Test that Rust is installed correctly:

rustc --version

You should see output like:

rustc 1.75.0 (82e1608df 2023-12-21)

Also verify that Cargo (Rust’s package manager) is working:

cargo --version

Step 6: Create Your First Rust Program

Let’s create a simple „Hello, World!“ program to confirm everything works:

mkdir ~/rust-projects
cd ~/rust-projects
cargo new hello-world
cd hello-world

Run your first Rust program:

cargo run

You should see:

   Compiling hello-world v0.1.0 (/home/user/rust-projects/hello-world)
    Finished dev [unoptimized + debuginfo] target(s) in 2.34s
     Running `target/debug/hello-world`
Hello, world!

What Gets Installed

Your Rust installation includes:

  • rustc: The Rust compiler
  • cargo: Package manager and build system
  • rustup: Toolchain installer and updater
  • rust-std: Standard library
  • rust-docs: Local documentation
  • clippy: Linting tool
  • rustfmt: Code formatter

All tools are installed in ~/.cargo/bin/ and added to your PATH.

Managing Rust Versions

Update Rust:

rustup update

Install specific versions:

rustup install beta
rustup install nightly

Switch between versions:

rustup default stable
rustup default beta
rustup default nightly

List installed toolchains:

rustup show

Important Notes

PATH Configuration: Rustup automatically adds ~/.cargo/bin to your PATH. If rustc --version doesn’t work after installation, you may need to restart your terminal or manually source the environment file.

Cross-compilation: Rust supports cross-compilation to many targets. You can add additional targets with:

rustup target add x86_64-pc-windows-gnu

Documentation: Access offline documentation anytime with:

rustup doc

Alternative Installation Methods

While rustup is recommended, you can also install Rust through:

Package Managers (may have older versions):

  • Ubuntu/Debian: sudo apt install rustc cargo
  • Fedora: sudo dnf install rust cargo
  • Arch: sudo pacman -S rust

Standalone Installers: Available from the official Rust website for specific platforms.

Troubleshooting

If you encounter issues:

  1. Command not found: Restart your terminal or run source ~/.cargo/env
  2. Compilation errors: Make sure build tools are installed (build-essential, etc.)
  3. Permission issues: Never run rustup with sudo; it should install to your home directory
  4. Network issues: Check your internet connection and firewall settings
  5. Old versions: Some package managers have outdated Rust versions; use rustup for latest releases

Uninstalling Rust

If you need to uninstall Rust installed via rustup:

rustup self uninstall

This removes all Rust toolchains and rustup itself.

Next Steps

Now that Rust is installed on your Linux system, you can:

  • Explore the official Rust Book: rustup doc --book
  • Try Rust by Example: rustup doc --rust-by-example
  • Join the Rust community forums and Discord
  • Start building your first Rust project with cargo new
  • Learn about Rust’s package ecosystem at crates.io

Keeping Rust Updated

Rust releases new versions every 6 weeks. Stay updated by running:

rustup update

This ensures you have the latest features, performance improvements, and security fixes.


Having trouble with your Rust installation on Linux? Leave a comment and we’ll help you troubleshoot!

 

Loading

Über chukfinley

I am a long time Linux user and FLOSS enthusiast. I use Debian with DWM. Furthermore, I know how to code in Python, Flutter, HTML (How to meet ladies). I also love minimalism.

Zeige alle Beiträge von chukfinley →

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert