How to Install Rust on Ubuntu 26.04 LTS with rustup or apt
Install the Rust toolchain on Ubuntu 26.04 LTS with rustup or apt, compile a first program with Cargo, and keep it up to date.
This guide installs the Rust toolchain (rustc, cargo and rustup) on Ubuntu 26.04 LTS, builds a first program and shows how to keep the toolchain current. The same steps work on Ubuntu 24.04 LTS; the differences are noted where they exist. Ubuntu 14.04 left standard support in 2019, and the rustup.sh script that older tutorials pipe into a shell has been replaced by the rustup installer described here.
You can install Rust in two ways. rustup is the method the Rust project documents: it installs the latest stable release into your home directory and updates it on demand. Ubuntu's own packages are older but are maintained through apt like the rest of the system. Pick one; mixing them leads to two different rustc binaries on your PATH.
Requirements
- A server running Ubuntu 26.04 LTS or 24.04 LTS.
- A regular user with
sudorights. The examples usedeploy. Rust itself does not need root. - Roughly 1.5 GB of free disk space for the toolchain and build artefacts of a small project.
Install the build prerequisites
Rust needs a linker to combine its compiled output into an executable, and many crates compile small pieces of C. The Rust documentation recommends installing a C compiler for both reasons; on Ubuntu that is the build-essential package.
sudo apt update
sudo apt install -y build-essential curl
Method 1: install Rust with rustup (recommended)
Run the installer as the user who will write Rust code, not with sudo:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
The installer shows what it is about to do and offers a menu. Press 1 (or Enter) for the standard installation. It downloads the current stable toolchain and puts the tools in ~/.cargo/bin.
For an unattended install, for example from a provisioning script, pass -y to accept the defaults:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
The installer adds ~/.cargo/bin to your PATH through your shell profile, which takes effect at the next login. To use Rust in the current session, load the environment file it created:
. "$HOME/.cargo/env"
Method 2: install Rust from the Ubuntu repositories
If you prefer packages that apt manages, Ubuntu ships the compiler and Cargo:
sudo apt install -y rustc cargo
Ubuntu 26.04 carries Rust 1.93 as its default rustc; 24.04 carries an older release. The version stays on that line for the life of the Ubuntu release, so a crate that declares a newer minimum Rust version will refuse to build. Ubuntu 26.04 also publishes versioned packages such as rustc-1.93 when you need a specific compiler.
Ubuntu also packages rustup itself (in the universe component, on both 24.04 and 26.04). That gives you an apt-managed rustup that still downloads toolchains from the Rust project:
sudo apt install -y rustup
rustup default stable
Do not install the rustup package alongside rustc and cargo from apt.
Verify the installation
rustc --version
cargo --version
Each command prints a version number followed by a commit hash and date, in the form rustc x.y.z (abcabcabc yyyy-mm-dd). If the shell reports command not found after a rustup install, ~/.cargo/bin is not on your PATH: check with echo $PATH, then log out and back in or source ~/.cargo/env again.
Build your first program
You can compile a single file directly with rustc:
mkdir -p ~/rust-test && cd ~/rust-test
nano main.rs
fn main() {
println!("Rust is installed and working.");
}
rustc main.rs
./main
Real projects use Cargo, which handles dependencies, builds and tests. Create a project, then build and run it in one step:
cd ~
cargo new hello
cd hello
cargo run
cargo new creates Cargo.toml (the project manifest) and src/main.rs. cargo run produces an unoptimised debug build in target/debug/. For a binary you intend to deploy, build with optimisations:
cargo build --release
./target/release/hello
The release binary is a single file linked against the system C library, so you can copy it to another server running the same Ubuntu release without installing Rust there.
Keep Rust up to date
A new stable Rust version is released every six weeks. With rustup, update all installed toolchains and rustup itself with:
rustup update
Useful related commands:
rustup showlists the installed toolchains and the active one.rustup component add clippy rustfmtadds the linter and formatter if your installation profile left them out.rustup docopens the offline copy of the documentation, which is only useful on a machine with a browser.
With the apt packages, Rust is updated together with the rest of the system by sudo apt update && sudo apt upgrade.
Uninstall Rust
A rustup installation removes itself, including every toolchain it downloaded:
rustup self uninstall
For the apt packages:
sudo apt remove --autoremove rustc cargo
The official Rust installation page and The Rust Programming Language book describe the installer in more detail.
Frequently asked questions
Should I run the rustup installer as root?
No. rustup installs into the home directory of the user who runs it, so each developer account gets its own toolchain and nobody needs root to update it. On a build server, create a dedicated unprivileged user and install Rust for that account.
Why does cargo fail with "linker cc not found"?
The system has no C compiler and linker. Install build-essential as shown above and run the build again. Crates that bind to system libraries such as OpenSSL additionally need pkg-config and the matching -dev package, for example libssl-dev.
Do I need Rust on the server that runs my program?
No. Rust compiles to a native executable. Build with cargo build --release on a development or build machine with the same architecture and a C library no newer than the target's, then copy the binary across. Only install the toolchain on servers that actually compile code.
How much memory does compiling need?
Small programs build comfortably on a 1 GB server, but large dependency trees can exhaust memory during linking. If the compiler is killed part-way through, add swap space or limit parallel jobs with cargo build -j 1.