How to Install Rust on Ubuntu 26.04 and 24.04

Share

To install Rust on Ubuntu 26.04 or 24.04, use the official rustup installer for the current stable toolchain, or APT for Ubuntu-managed packages. Canonical also maintains a rustup Snap. Choose one route, then build the practice project below to confirm the compiler and linker work together.

Rust is a programming language used for command-line tools, services and systems software. rustc compiles your code, Cargo builds projects and manages their dependencies, and rustup manages compiler versions. If a step fails, leave a comment with the error or contact us.

Before you begin
  • Use Ubuntu 26.04 or 24.04 Desktop or Server, internet access, and a sudo-enabled account for Ubuntu packages. Commands use Bash.
  • Run rustup, Cargo and your projects as your normal user. Do not use sudo with the Rust installer or cargo build.
  • If Rust is already installed, identify its source before adding another copy. PATH determines which compiler runs.
  • In WSL, use these commands inside the Ubuntu terminal. They install Linux Rust; native Windows Rust uses a separate installer.

1. Choose how to install Rust

Method Choose it when How it updates
Upstream rustup (recommended) You want current stable Rust, matching editor components and optional nightly or pinned toolchains. rustup update
Ubuntu APT You need Ubuntu-managed compiler packages and the available version meets your project requirements. Ubuntu package updates
Canonical rustup Snap You prefer a packaged rustup manager and accept classic confinement. Snap updates the manager; rustup update updates toolchains.

The Rust project recommends rustup. Ubuntu documents both its archive packages and the rustup Snap. The Snap is published by Canonical and is not maintained or endorsed by the Rust Foundation. These are different ways to obtain the tools, not different Rust languages.

Check your release and any existing installation

Open a terminal with Ctrl+Alt+T on Ubuntu Desktop. Run these checks:

Ubuntu terminal
cat /etc/os-release
dpkg --print-architecture
type -a rustc cargo rustup

Command-not-found messages are normal on a fresh system. amd64 means 64-bit Intel/AMD; arm64 means 64-bit ARM. Paths under ~/.cargo/bin, /usr/bin and /snap/bin usually indicate upstream rustup, APT and Snap respectively. If anything is installed, check its version and use the troubleshooting section before switching. APT can also provide rustup itself, so confirm ownership with dpkg -S /usr/bin/rustup if that path appears.

2. Install Rust with the official rustup installer

Step 1: Install the build and download tools

Refresh Ubuntu package information and install a C/C++ build environment, curl and trusted HTTPS certificates:

Ubuntu terminal
sudo apt update
sudo apt install build-essential curl ca-certificates pkg-config

build-essential supplies the compiler and linker needed to produce Linux executables and build crates containing C/C++ code. pkg-config helps locate native libraries; it does not install those libraries itself. Review APT’s proposed changes before confirming.

Step 2: Download, inspect and run the installer

The official installer downloads and runs code on your machine. This version saves the script first so you can inspect it before execution. Keep these steps in the same terminal:

Ubuntu terminal
rust_setup_dir=$(mktemp -d) &&
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o "$rust_setup_dir/rustup-init.sh" &&
less "$rust_setup_dir/rustup-init.sh"

Press q to leave less. If less is unavailable, open the saved file in a text editor. Continue only after the download succeeds and you are comfortable running the script. The HTTPS options protect the download connection; they are not an independent code audit.

Ubuntu terminal
sh "$rust_setup_dir/rustup-init.sh" --profile default --default-toolchain stable

Choose 1) Proceed with standard installation when prompted. The default profile includes Cargo, rustc, rustfmt, Clippy and local documentation. Accepting this installer as your normal user installs into your account, normally ~/.cargo and ~/.rustup. If it reports an existing installation or fails midway, stop and read the error before retrying.

Step 3: Load Rust into this terminal

Load the environment file the successful installer created:

Ubuntu terminal
. "$HOME/.cargo/env"
rustc --version
cargo --version
rustup show active-toolchain

Both version commands should print a release number. The active toolchain should normally begin with stable-. Exact versions and the architecture suffix vary. Opening a new terminal usually loads the installer’s PATH changes; if it does not, see the PATH fix below. Zsh and Fish use their own startup configuration.

Next: build your first project

If these checks succeed, jump to the project exercise. You have completed this installation route; the next two sections are alternatives.

3. Alternative: install Rust and Cargo with APT

Step 1: Check Ubuntu’s available packages

Inspect the local candidates before deciding whether Ubuntu’s compiler is new enough:

Ubuntu terminal
sudo apt update
apt-cache policy rustc cargo

The unversioned package listings currently select Rust/Cargo 1.93.1 on Ubuntu 26.04 and 1.75.0 on Ubuntu 24.04. These are package-listing observations, not a promise about your enabled repositories. APT security revisions and versioned compiler packages are separate from the default upstream release number.

Step 2: Install the compiler, Cargo and build prerequisites

Use Ubuntu’s repositories:

Ubuntu terminal
sudo apt install rustc cargo build-essential pkg-config ca-certificates
rustc --version
cargo --version
command -v rustc
command -v cargo

Commands should normally resolve under /usr/bin. Cargo pulls in a compiler dependency, but listing both packages makes the installation explicit. This route does not need ~/.cargo/env or a rustup command. Choose rustup instead if the project needs a newer compiler or multiple toolchains.

Step 3: Add formatting and linting tools if needed

These optional Ubuntu packages provide cargo fmt and cargo clippy:

Ubuntu terminal
sudo apt install rustfmt rust-clippy

If an optional package has no candidate, check that the Universe repository is enabled using Ubuntu’s Software & Updates application, refresh APT, and check again. Keep the tools from the same package source as the compiler. Continue with the project exercise after installing.

4. Alternative: install Canonical’s rustup Snap

Use this route instead of the upstream script or Ubuntu compiler packages. Classic confinement gives the development tools broad access under your account permissions. Snap support must be installed and running; a minimal server or WSL environment may need Snap setup first.

Step 1: Check the publisher and install rustup

Check that the package is published by the verified Canonical account:

Ubuntu terminal
snap version
snap info rustup
sudo snap install rustup --classic

The rustup Snap listing identifies its publisher. Installing the manager alone does not finish installing the Rust compiler.

Step 2: Install a stable toolchain as your normal user

Do not add sudo to these rustup commands:

Ubuntu terminal
rustup toolchain install stable --profile default
rustup default stable
rustc --version
cargo --version
rustup show active-toolchain
type -a rustc cargo rustup

The Snap supplies command aliases such as /snap/bin/rustc and /snap/bin/cargo. If another installation appears first, resolve that conflict before continuing. If Snap’s PATH is missing, sign out and back in. Unlike the script route, this installation does not require sourcing ~/.cargo/env.

Two update mechanisms

Snap refreshes the packaged rustup manager. Run rustup update to update its downloaded Rust toolchains. Do not use rustup self update for this package; self-updating is disabled in Canonical’s build.

5. Build, run and test your first Rust project

Complete one installation method first. The example has no third-party crate dependencies, so it can build without downloading libraries once the toolchain is installed. Keep the project steps in the same terminal.

Step 1: Create a practice project without overwriting files

Make a unique directory under your home folder, then create a binary project inside it:

Ubuntu terminal
rust_demo_dir=$(mktemp -d "$HOME/rust-demo.XXXXXX") &&
cd "$rust_demo_dir" &&
cargo new hello-ubuntu --bin --edition 2021 --vcs none &&
cd hello-ubuntu

The explicit 2021 edition keeps this example compatible with Ubuntu 24.04’s default compiler as well as newer Rust. Newer Cargo may otherwise choose edition 2024. --vcs none skips creating a Git repository; it is not needed to test the compiler. If any command fails, stop here.

Step 2: Run the generated program

Cargo created the starter program for you:

Ubuntu terminal
cargo run

This compiles src/main.rs, links an executable and runs it. You should see build messages followed by this line:

Hello, world!
Project item What it contains
Cargo.toml The package name, edition and dependency declarations.
src/main.rs The source code of this executable.
Cargo.lock Resolved dependency versions, created during the build. Keep it in version control for an application.
target/ Generated build files. You can rebuild these from the source.
Step 3: Build an optimized executable

A release build enables optimizations. Run the generated file directly:

Ubuntu terminal
cargo build --release
./target/release/hello-ubuntu

Expect the same greeting. ./ means to run a file relative to this directory. The binary is for the current Linux architecture; it is not automatically a Windows or ARM executable.

Step 4: Format, lint and check for tests

The default rustup profile includes the first two tools. APT users need the optional packages above:

Ubuntu terminal
cargo fmt --check
cargo clippy
cargo test

A formatting check succeeds without changing source files. Use cargo fmt when you want to reformat them in place. Clippy reports code suggestions. The untouched starter has no tests, so cargo test reporting zero tests is expected; it does not establish that an application has been tested.

You can reopen this practice project later by locating its rust-demo.* folder in your home directory and entering hello-ubuntu. Keep your source and Cargo files; the installer does not manage your projects.

6. Add editor support and development tools

For VS Code: install the rust-analyzer extension

In VS Code, open Extensions and search for rust-analyzer. Check that the extension ID is rust-lang.rust-analyzer, then open the whole project folder containing Cargo.toml.

Ubuntu terminal
rustup component add rust-src

The command applies to rustup users and adds Rust’s standard-library source. The VS Code extension already bundles the rust-analyzer server; installing a separate server component is normally unnecessary. Restart an editor opened before the Rust installation if it cannot find Cargo. APT users should check the extension’s toolchain requirements if their packaged compiler is older.

For other editors: add the server and standard-library source

If your LSP-capable editor needs a rust-analyzer executable, rustup can install it:

Ubuntu terminal
rustup component add rust-analyzer rust-src
rust-analyzer --version

Configure that editor to use the installed server. Do not run this rustup command for an APT-only compiler installation. Follow the rust-analyzer installation guidance for editor-specific requirements.

Check or restore rustup’s formatter and linter

If you installed the minimal profile, add the missing components:

Ubuntu terminal
rustup component add rustfmt clippy
rustup component list --installed

Components belong to a particular toolchain. A project using a pinned toolchain may need its own matching components. You do not need nightly for normal formatting and Clippy use.

Rust command-line applications installed with cargo install normally go into ~/.cargo/bin, independently of your project’s target directory. APT and Snap users may need to add that directory to their shell PATH if they later install such applications. Run these tools as your normal user.

7. Update Rust using your installation method

Upstream rustup: update the toolchains

This checks installed toolchains and updates moving channels such as stable and nightly:

Ubuntu terminal
rustup update
rustc --version
rustup show active-toolchain

An exact numbered toolchain stays on that release. A project override can still select an older compiler after stable updates. Upstream rustup normally checks for its own update too; rustup self update updates only the manager, not your project dependencies.

APT: update Ubuntu’s packages

Refresh package information, then request upgrades to the installed compiler and Cargo:

Ubuntu terminal
sudo apt update
sudo apt install --only-upgrade rustc cargo
rustc --version
cargo --version

Review the package transaction. Update rustfmt and rust-clippy through APT too if installed. Updating these packages does not guarantee a switch to the latest upstream Rust branch. Use normal Ubuntu updates to keep their dependencies maintained.

Snap: refresh the manager and update the toolchains

Snap normally refreshes automatically. To request an update explicitly:

Ubuntu terminal
sudo snap refresh rustup
rustup update
rustup show active-toolchain

Do not confuse the rustup package version shown by snap list rustup with the compiler version shown by rustc --version. None of these commands updates dependencies in Cargo.lock; use your project’s dependency update and test process for that.

8. Use nightly or pin Rust for one project

This section applies to rustup installations. Keep stable as your default unless a project explicitly needs another toolchain.

Try nightly for a single build

Install nightly alongside stable and select it for one command from your project directory:

Ubuntu terminal
rustup toolchain install nightly
rustup toolchain list
cargo +nightly build

The +nightly selector affects this command. It does not replace your stable default. Nightly may contain regressions or temporarily lack optional components. Remove it later with rustup toolchain uninstall nightly if no project needs it.

Pin a toolchain for a shared project

For an existing project, first inspect any rust-toolchain.toml or rust-toolchain file and follow its requirements. For a new pin, run rustc --version, then use its exact numeric release in this file:

The block below is a template for rust-toolchain.toml, not a shell command. Replace YOUR.EXACT.VERSION, and edit or create the file deliberately instead of overwriting an existing one.

rust-toolchain.toml template
[toolchain]
channel = "YOUR.EXACT.VERSION"
profile = "default"
components = ["rust-src"]

For example, a release output beginning rustc 1.93.1 maps to channel = "1.93.1"; choose the version your project actually supports. Commit the toolchain file alongside your application’s Cargo.lock. Rustup can download a missing pinned toolchain when you next build. A pin improves consistency but needs deliberate updates for fixes.

Ubuntu terminal
rustup show active-toolchain
rustup override list

A local directory override or RUSTUP_TOOLCHAIN setting can take precedence over a project file. To remove a directory override, run rustup override unset in that directory. See the toolchain selection rules. Cargo.toml’s rust-version declares a minimum supported compiler; it does not install or pin that compiler.

9. Optional: build a Windows executable from Ubuntu

Use this rustup example for the dependency-free practice project when you need a 64-bit Windows GNU executable. It adds a cross-linker and a target standard library. Native-library dependencies need their own Windows-compatible builds; adding a Rust target alone does not supply those libraries.

Step 1: Add the Windows linker and Rust target

Run this in the project directory, with its required rustup toolchain active:

Ubuntu terminal
sudo apt install gcc-mingw-w64-x86-64
rustup target add x86_64-pc-windows-gnu
rustup target list --installed

Target lists belong to the active toolchain. If you later change toolchains, add the target to the newly selected one too.

Step 2: Build with an explicit linker

The environment setting chooses the linker for this command without overwriting Cargo configuration files:

Ubuntu terminal
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER=x86_64-w64-mingw32-gcc cargo build --release --target x86_64-pc-windows-gnu

The example executable appears at target/x86_64-pc-windows-gnu/release/hello-ubuntu.exe. Test it on Windows; Ubuntu cannot normally run a Windows .exe directly. This GNU-target workflow does not replace native Windows MSVC setup.

Step 3: Remove the optional target when no longer needed

Remove it only if no project using this toolchain needs it:

Ubuntu terminal
rustup target remove x86_64-pc-windows-gnu

If no other work needs MinGW, review sudo apt remove gcc-mingw-w64-x86-64. Removing the metapackage may leave its underlying compiler packages installed; preview sudo apt autoremove --dry-run before considering additional cleanup.

10. Fix common Rust installation and build errors

Issue 1: cargo, rustc or rustup is not found

For a successful upstream-script installation, first check the files exist, then load its environment if present:

Ubuntu terminal
ls -l "$HOME/.cargo/env" "$HOME/.cargo/bin/rustup"
[ -f "$HOME/.cargo/env" ] && . "$HOME/.cargo/env"
hash -r
type -a rustc cargo rustup

If the file is missing, inspect the installer’s error before retrying the installation. If a new terminal still loses the commands, inspect the startup file used by your shell. Bash normally uses ~/.bashrc for interactive terminals and ~/.profile for login settings; do not keep appending duplicate PATH lines. Snap users should check /snap/bin and their package aliases, while APT users should check that the package installation finished.

Issue 2: Rust still shows the old version

Find every command and check the toolchain selected inside the affected project:

Ubuntu terminal
type -a rustc cargo rustup
rustc --version
rustup show active-toolchain
rustup override list

The last two commands require rustup. An APT path before a rustup proxy, a project pin or a directory override can explain the result. Choose the installation you intend to keep. Before removing Ubuntu packages, preview sudo apt remove --simulate rustc cargo and review reverse dependencies. Do not delete /usr/bin files manually. After a deliberate method switch, run hash -r and verify again.

Issue 3: linker cc not found

Rust needs a working system linker even for the greeting example. Install Ubuntu’s standard build tools, then retry from the project directory:

Ubuntu terminal
sudo apt install build-essential
cc --version
cargo build

If the error names a cross-linker, use the package and target-specific linker setting for that target instead. Rustup’s target command installs Rust libraries, not the external linker.

Issue 4: OpenSSL or pkg-config cannot be found

When a Linux dependency such as openssl-sys specifically reports missing OpenSSL development files, install both the headers and discovery tool:

Ubuntu terminal
sudo apt install pkg-config libssl-dev
pkg-config --modversion openssl
cargo build

These Ubuntu packages fix a native Linux build; they are not Windows-target libraries. Other crates can need SQLite, CMake or additional packages. Read the failing crate’s build instructions rather than installing unrelated toolchains. The OpenSSL crate documentation describes its requirements.

Issue 5: a crate requires a newer Rust version or edition

Read the minimum version in the error. For rustup installations, update stable and test it explicitly:

Ubuntu terminal
rustup update stable
cargo +stable build

If that succeeds, review the project’s pin with its maintainers before changing it. APT users may need to switch to rustup after checking package dependencies. Edition 2024 needs Rust 1.85 or newer; the first-project example deliberately uses edition 2021. Do not suppress a minimum-version error and assume the compiler can build unsupported code.

Issue 6: the installer reports an HTTPS certificate error

Check your system date and Ubuntu’s certificate bundle first:

Ubuntu terminal
date -Is
sudo apt install --reinstall ca-certificates
curl --proto '=https' --tlsv1.2 -fsSI https://sh.rustup.rs

Correct an inaccurate system clock and retry the original download once HTTPS works. A managed network may require your organization’s trusted certificate or proxy settings. Do not use curl -k or disable certificate verification as an installation fix.

Issue 7: permission denied during a build

Work in a folder owned by your normal account and inspect any custom Rust directories:

Ubuntu terminal
pwd
ls -ld . "$HOME/.cargo" "$HOME/.rustup"
printf 'CARGO_HOME=%s\nRUSTUP_HOME=%s\n' "${CARGO_HOME:-not set}" "${RUSTUP_HOME:-not set}"

Some paths can be absent for APT users. If earlier sudo commands created root-owned project or cache files, correct only the identified files after checking their ownership. Do not run Cargo as root or recursively change ownership of unrelated directories.

Resume an interrupted installation

After fixing network, certificate or disk-space errors, retry the same method. If upstream rustup is installed but stable is incomplete, finish its toolchain and verify it:

Ubuntu terminal
rustup toolchain install stable --profile default
rustup default stable
rustc --version
cargo --version

If rustup itself is absent, repeat the inspected installer route instead. For APT, resolve the reported package error and rerun the install command. Then repeat the first-project build. Avoid switching methods midway through a repair.

11. Remove Rust using the matching method

Upstream installer: uninstall rustup and its data

Back up anything you need from the Cargo and Rustup directories first. Uninstall removes managed toolchains, Cargo caches and applications installed into Cargo’s bin directory. Your source projects elsewhere remain. Custom CARGO_HOME or RUSTUP_HOME locations change which directories are affected.

Ubuntu terminal
rustup self uninstall

Read and confirm the prompt. Open a new terminal afterwards and inspect your shell startup files for any remaining reference to a removed environment file. Do not run this package-independent removal command for an APT- or Snap-managed rustup executable.

APT: preview package removal

List the installed Rust packages and preview the transaction. Include optional formatter and linter packages only if you installed them:

Ubuntu terminal
dpkg-query -W rustc cargo rustfmt rust-clippy
sudo apt remove --simulate rustc cargo

A missing optional package can produce a dpkg-query warning. If the proposed removal is acceptable, run:

Ubuntu terminal
sudo apt remove rustc cargo

On Ubuntu 26.04, versioned compiler packages may remain after removing the default selectors. Preview sudo apt autoremove --dry-run and inspect the list before any cleanup. APT removal does not delete your source projects or user Cargo caches.

Snap: remove downloaded toolchains, then the package

First inspect the toolchains and remove only the ones you no longer need:

Ubuntu terminal
rustup toolchain list
rustup toolchain uninstall stable

The second command removes the stable toolchain; repeat with other exact listed names only when no project needs them. You can keep the toolchain data if you plan to reinstall the manager. Then remove the Snap:

Ubuntu terminal
sudo snap remove rustup

Removing the Snap alone does not promise to clear user data stored outside Snap’s managed directories, such as ~/.rustup or ~/.cargo. Inspect those directories and any custom locations before considering further cleanup. Do not blindly delete ~/.cargo: it can contain separately installed applications and credentials.

Ubuntu terminal
hash -r
type -a rustc cargo rustup

A command-not-found message is expected after removal if no other installation remains. If a command is still present, its path identifies the next installation to inspect.

12. Helpful Rust resources

Keep these references nearby

Frequently asked questions

Does installing Rust also install Cargo?

Yes. The default rustup toolchain includes Cargo. In Ubuntu APT, install cargo alongside rustc; the cargo package also depends on a Rust compiler. You do not need a separate third-party Cargo installer.

Should I use rustup or APT on Ubuntu?

Use rustup when you need current upstream Rust, multiple toolchains or matching development components. Use APT when Ubuntu package management is your priority and its available compiler meets your project requirements. Choose one primary route and verify which commands your shell finds.

Do I need sudo to build a Rust project?

No. Run Cargo and rustup as your normal user in a directory you own. Sudo is needed for system packages such as build-essential, not for ordinary Rust builds or per-user toolchains.

Can I install Rust inside Ubuntu on WSL?

Yes. Use the Linux installation steps from the Ubuntu terminal. This installs a Linux toolchain inside that environment. Native Windows development uses a separate Windows toolchain and its own build prerequisites.

Why is Rust older after I run an update?

Your shell may be finding another installation, or the project may select a pinned toolchain or directory override. APT also follows Ubuntu package versions rather than always selecting the latest upstream release. Check command paths and, for rustup, the active toolchain inside the project.

Will uninstalling Rust delete my projects?

Source projects outside the managed installation directories remain. Upstream rustup uninstallation removes its managed toolchains and Cargo home, which can include installed command-line applications and caches. Back up needed data and check any custom installation directories before removal.

Related Ubuntu guides: Install Visual Studio Code · Install and use curl · Check your Ubuntu version.