UbuntuUbuntu Based

How To Install Rust on Ubuntu 24.04 LTS

Install Rust on Ubuntu 24.04

In this tutorial, we will show you how to install Rust on Ubuntu 24.04 LTS. Rust, developed by Mozilla Research, is a systems programming language that emphasizes safety, concurrency, and performance. Its innovative features, such as memory safety without garbage collection and fearless concurrency, make it an attractive choice for developers working on system-level projects, web applications, and everything in between.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Rust programming language on Ubuntu 24.04 (Noble Numbat). You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.

Prerequisites

  • A server running one of the following operating systems: Ubuntu and any other Debian-based distribution like Linux Mint.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • Basic familiarity with the command line interface.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies.
  • An Ubuntu 24.04 system with root access or a user with sudo privileges.

Install Rust on Ubuntu 24.04

Step 1. Updating the Package Repository.

Before installing any new software, it’s crucial to update your system packages to the latest versions. This ensures compatibility and security.

sudo apt update
sudo apt upgrade

The apt update command refreshes the package list while apt upgrade installing the available updates. This step helps resolve any dependency issues and provides access to the latest security patches and bug fixes.

Step 2. Installing Rust Programming Language.

  • Method 1: Installing Rust Using APT

The Advanced Package Tool (APT) is Ubuntu’s default package manager, offering a straightforward way to install Rust. While this method is simple, it may not always provide the latest version of Rust.

Install the Rust compiler using APT:

sudo apt install rustc

When prompted, enter ‘Y’ to confirm the installation.

After the installation completes, verify that Rust has been installed correctly by checking its version:

rustc --version

You should see output similar to:

rustc 1.xx.x (xxxxxxxx 20xx-xx-xx)

Installing Rust via APT is quick and integrates well with Ubuntu’s package management system. However, this method may not provide the most up-to-date version of Rust, and it doesn’t include additional tools like Cargo, Rust’s package manager and build system.

  • Method 2: Installing Rust Using Rustup

Rustup is the official Rust toolchain installer, offering more flexibility and control over your Rust installation. It allows you to easily manage multiple Rust versions and components.

First, ensure you have the necessary dependencies:

sudo apt install curl build-essential gcc make

Next, download and run the Rustup installer script:

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

The installer will present you with installation options. For most users, the default option (1) is suitable:

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation

Press Enter to select the default option.

After installation, you’ll need to set up your current shell to use Rust. Run the following command:

source $HOME/.cargo/env

Alternatively, you can log out and log back into your system to apply the changes automatically.

Confirm that Rustup and Rust have been installed correctly:

rustc --version
cargo --version

You should see version information for both the Rust compiler (rustc) and Cargo, the Rust package manager.

Step 3. Configuring PATH.

Rustup typically adds the necessary directories to your PATH automatically. However, if you encounter issues, you can manually add the following line to your ~/.bashrc or ~/.zshrc file:

export PATH="$HOME/.cargo/bin:$PATH"

Step 4. Setting Up Cargo.

Cargo, Rust’s package manager and build system, is installed automatically with Rustup. To start a new Rust project:

cargo new my_project
cd my_project
cargo build
cargo run

These commands create a new project, build it, and run it, respectively.

To keep Rust up-to-date, periodically run:

rustup update

Step 5. Verifying Rust Installation.

To ensure Rust is working correctly, let’s create and run a simple program:

nano hello.rs

Add the following code:

fn main() {
println!("Hello idroot.us, Ubuntu 24.04! Rust is successfully installed.");
}

Compile the program:

rustc hello.rs

Run the compiled program:

./hello

If everything is set up correctly, you should see the message “Hello idroot.us, Ubuntu 24.04! Rust is successfully installed.” printed on the console.

Congratulations! You have successfully installed Rust. Thanks for using this tutorial for installing the Rust programming language on the Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the official Rust website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button