Install Rust on Ubuntu 22.10/22.04/20.04
If you’re looking to get your hands dirty with low‑level systems code, this guide walks you through the quickest way to install the Rust compiler and its package manager, Cargo, on any recent Ubuntu release.
Why Rust Matters for Everyday Developers
Rust isn’t just a niche hobby language; it’s the go‑to tool for writing fast, safe networking tools and CLI apps. On Ubuntu, installing it is as simple as running a few commands—no juggling of mirrors or messing with package versions.
Check Your Base System First
Before you fire up a shell, confirm you have an updated system:
sudo apt update && sudo apt upgrade -y
You’ll save yourself later headaches if the kernel and libraries are current. I once tried compiling a Rust project on a machine that had an old glibc version; the build would crash mid‑compile with cryptic errors.
Install the Minimal Toolchain via apt
Ubuntu’s repositories ship a precompiled Rust binary. This is handy for quick experimentation:
sudo apt install curl build-essential curl https://sh.rustup.rs -sSf | sh -s -- -y
The build-essential package pulls in gcc and make—necessary if you want to compile native extensions or run benchmarks.
Why this matters? The Ubuntu repo version may lag behind the latest stable release. If you need cutting‑edge features, skip ahead to the next section.
Use Rustup for Up‑to‑Date Toolchains
Rustup is the official installer and version manager. It keeps your compiler, Cargo, and standard library in sync:
curl https://sh.rustup.rs -sSf | sh
During installation, pick the default option (just press enter). Rustup will add a line to your .profile or .zshrc, ensuring the rustc and cargo binaries are on your $PATH.
After that, reload your shell:
source ~/.profile # or exec $SHELL
Verify the Installation
Run these two commands to confirm everything is wired correctly:
rustc --version cargo --version
You should see something like rustc 1.70.0 (90e6e7a42 2023-10-23) and cargo 1.70.0. If you get a “command not found” error, double‑check that Rustup added the path line to your shell profile.
Create a Simple Hello World Project
To make sure Cargo is working:
cargo new hello_world --bin cd hello_world cargo run
The console should print Hello, world!. If it fails because of missing headers or libraries, that’s usually a clue you need to install the corresponding system packages (libssl-dev, pkg-config, etc.).
Common Pitfall: Mixed Toolchains
I’ve seen users accidentally leave both the Ubuntu‑repo Rust and Rustup installed side by side. This can cause confusing “could not find rustc” errors when running scripts that assume one path. Clean it up with:
sudo apt remove rustc cargo
Then rely solely on Rustup.
Optional: Switching to Nightly Builds
If you’re chasing the latest language features, switch to nightly:
rustup toolchain install nightly rustup default nightly
Remember that nightly can be unstable; use it only for experimental projects or when a specific feature is required.
Installing Rust on Ubuntu 22.10, 22.04, or 20.04 isn’t rocket science—just a couple of commands and some sanity checks.