Rust is a fast, memory-safe systems programming language. It catches whole classes of bugs, such as use-after-free and data races, at compile time without a garbage collector, which is why it’s used for command-line tools, web services, embedded systems and even the Linux kernel. Rust comes with Cargo, its build tool and package manager, and installs through rustup, the official toolchain installer.
This guide shows how to install the latest Rust on Ubuntu 26.04 LTS (Resolute Raccoon) with rustup, create and run your first project, manage toolchains and components, and, as an alternative, install the older Rust packaged by Ubuntu.
Rust is already part of Ubuntu 26.04 itself: the release uses Rust-based system tools such as the Rust coreutils and sudo-rs. Those are system components, though, not a development toolchain, so you still need to install Rust to build your own programs.
Prerequisites
- A system running Ubuntu 26.04 (desktop or server).
- A user account with sudo privileges for installing build tools. Rust itself installs in your home directory.
- An internet connection.
Which Installation Method Should You Use?
| Method | Rust version | Best for | |
|---|---|---|---|
| Method 1: rustup (Steps 1–5) | Latest stable (Rust 1.100 at the time of writing), updated with one command | Development. Lets you switch between stable, beta, nightly and older versions. | Go to Method 1 → |
| Method 2: Ubuntu packages | Rust 1.93 | Building Ubuntu packages, or systems that must only use the Ubuntu archive. | Go to Method 2 → |
Pick one method per user. Rust releases a new stable version every six weeks, and many crates require a recent compiler, so most developers should use rustup. See the Rust release history for the current version.
Step 1 of 5Install the Build Tools
Method 1 (rustup) covers Steps 1 to 5. Step 1 is also needed if you choose Method 2.
Rust needs a C linker to produce executables, and many crates compile small pieces of C code. Install build-essential (GCC, make and the C library headers) and curl:
sudo apt updatesudo apt install build-essential curl -y
Crates that talk to TLS or other system libraries, such as reqwest with OpenSSL, also need pkg-config and the library headers. Installing them now saves a confusing build error later:
sudo apt install pkg-config libssl-dev -y
Step 2 of 5Install Rust with rustup (Method 1)
Download and run the official rustup installer as your normal user. Don’t use sudo: rustup installs everything into ~/.rustup and ~/.cargo in your home directory.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
The installer shows where it will put the files and asks how to proceed. Press 1 and then Enter to accept the default installation. It installs the stable toolchain with the default profile: rustc, cargo, the standard library, the documentation, rustfmt and clippy.
When it finishes, the installer adds ~/.cargo/bin to your PATH for new login shells. To use Rust in the current terminal right away, load the environment file:
source "$HOME/.cargo/env"
Note: To install without any prompts, for example in a script or Dockerfile, add -s -- -y: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y.
Step 3 of 5Verify the Installation
Check that the compiler, Cargo and rustup are available:
rustc --versioncargo --versionrustup --version
rustc --version should report the current stable release, for example rustc 1.100.0. To see which toolchains are installed and which one is active, run:
rustup show
Step 4 of 5Create and Run Your First Rust Project
Cargo creates a new project with a ready-to-run “Hello, world!” program:
cargo new hello-rustcd hello-rust
The project contains a Cargo.toml file with the project’s name, version and dependencies, and the source code in src/main.rs:
fn main() {
println!("Hello, world!");
}
Build and run it in one step:
cargo run
Cargo compiles the program and prints Hello, world!. Development builds go to target/debug/. For an optimized binary to deploy, build in release mode; the program is written to target/release/hello-rust:
cargo build --release./target/release/hello-rust
Step 5 of 5Add Dependencies and Use the Built-in Tools
Libraries in Rust are called crates and come from crates.io. cargo add adds one to Cargo.toml, and the next build downloads and compiles it:
cargo add anyhowcargo build
The default rustup installation also includes a formatter and a linter. Use them before every commit:
| Command | What it does |
|---|---|
cargo fmt | Formats the code in the standard Rust style |
cargo clippy | Lints the code and suggests more idiomatic or safer alternatives |
cargo check | Checks the code for errors quickly, without building a binary |
cargo test | Builds and runs the project’s tests |
cargo doc --open | Builds documentation for your project and its dependencies |
Manage Rust Toolchains with rustup
rustup can install several versions side by side. These are the commands you’ll use most:
| Command | What it does |
|---|---|
rustup update | Update all installed toolchains (and rustup itself) |
rustup toolchain install nightly | Install the nightly toolchain alongside stable |
rustup default stable | Choose the toolchain used by default |
rustup override set nightly | Use a different toolchain only in the current project directory |
rustup component add rust-analyzer | Add the language server used by editors such as VS Code |
rustup target add x86_64-unknown-linux-musl | Add a target for building fully static Linux binaries |
A project can also pin its toolchain with a rust-toolchain.toml file in its root directory, so everyone on the team builds with the same version.
Method 2: Install Rust from the Ubuntu Repositories
If you need Rust only to build software from source and don’t mind an older version, install the compiler and Cargo packaged by Ubuntu:
sudo apt install rustc cargo -yrustc --version
Ubuntu 26.04 ships Rust 1.93 as rustc, plus versioned packages such as rustc-1.91 and rustc-1.92 for projects that need an older compiler.
Note: Don’t mix both methods for the same user. If you later switch to rustup, its ~/.cargo/bin comes first on the PATH, but removing the Ubuntu packages avoids confusion about which cargo runs.
Update Rust
With rustup, updating to a new stable release takes a single command. Rust ships one every six weeks:
rustup update
With the Ubuntu packages, Rust is updated along with the rest of the system by sudo apt upgrade, but stays on the same version line.
Troubleshooting
- error: linker `cc` not found: the C toolchain is missing. Install it with
sudo apt install build-essential. - cargo: command not found after installing: open a new terminal, or run
source "$HOME/.cargo/env". If it still fails, make sure~/.cargo/binis on your PATH. - failed to run custom build command for `openssl-sys`: install
pkg-configandlibssl-dev. - A crate requires a newer rustc: run
rustup update. With the Ubuntu packages, switch to rustup to get the latest compiler. - Permission errors: rustup and Cargo should never be run with sudo. If you used sudo by mistake, remove the files it created in your home directory and reinstall as your user.
Uninstall Rust
To remove rustup and every toolchain it installed, run:
rustup self uninstall
To remove the Ubuntu packages instead:
sudo apt remove rustc cargo -ysudo apt autoremove -y
Conclusion
You now have the latest Rust toolchain on Ubuntu 26.04, with Cargo for building projects and managing crates, and rustup for updates and multiple toolchains. To see what changed in the latest release, read what’s new in Rust 1.100. Running Ubuntu 24.04? Follow how to install Rust on Ubuntu 24.04 instead.
How did it make you feel?
