How to Install Rust on Ubuntu 25.04

Rust is a multi-paradigm, general-purpose programming language that emphasizes performance, type safety, and concurrency. It enforces memory safety—ensuring that all references point to valid memory—without requiring the use of a garbage collector or reference counting present in other memory-safe languages.

Install Rust

Install Rust using the rustup command line tool:

Run the following command to download and start the installer:

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

You’ll see output similar to:

Welcome to Rust!

This will download and install the official compiler for the Rust programming language, and its package manager, Cargo.

Rustup metadata and toolchains will be installed into the Rustup home directory, located at:
/root/.rustup

The Cargo home directory is located at:
/root/.cargo

The cargo, rustc, rustup and other commands will be added to Cargo's bin directory:
/root/.cargo/bin

This path will then be added to your PATH environment variable by modifying:
/root/.profile
/root/.bashrc

You can uninstall at any time with rustup self uninstall.

Current installation options:
1) Proceed with standard installation (default - just press enter)
2) Customize installation
3) Cancel installation

Choose option 1 to proceed.

>1

Once installation completes, you'll see something like:

info: default toolchain set to 'stable-x86_64-unknown-linux-gnu'

  stable-x86_64-unknown-linux-gnu installed - rustc 1.86.0 (05f9846f8 2025-03-31)

Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).

To configure your current shell, you need to source
the corresponding env file under $HOME/.cargo.

This is usually done by running one of the following (note the leading DOT):
. "$HOME/.cargo/env"            # For sh/bash/zsh/ash/dash/pdksh
source "$HOME/.cargo/env.fish"  # For fish
source "$HOME/.cargo/env.nu"    # For nushell

Add Rust to your PATH:

source "$HOME/.cargo/env"

Verify the Installation

Check the installed Rust version:

rustc --version

Expected output:

rustc 1.86.0 (05f9846f8 2025-03-31)

Installing a Compiler and Build Tools

Update the package index:

apt update && apt upgrade

Install required development tools:

apt install build-essential

Creating, Compiling, and Running a Test Program

Create a project directory:

mkdir -p ~/rustprojects/testdir
cd ~/rustprojects/testdir

Create a file named test.rs:

nano test.rs

Paste the following code:

fn main() {
    println!("Congratulations! You have installed your Rust program and it works.");
}

Save and close the file. Then compile it:

rustc test.rs

Run the program:

./test

Expected output:

Congratulations! You have installed your Rust program and it works.

Updating Rust

To update Rust in the future:

rustup update

Output:

root@server:~/rustprojects/testdir# rustup update
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: checking for self-update

  stable-x86_64-unknown-linux-gnu unchanged - rustc 1.86.0 (05f9846f8 2025-03-31)

info: cleaning up downloads & tmp directories

🎉 You’ve successfully installed and tested Rust on Ubuntu 25.04.


CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!

1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month

Available Locations: LAX | MIA | ATL | FRA | AMS