How to Install Rust on Ubuntu 18.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 the Rust using rustup command line tool,

Run the below command to download the rustup command,

curl --proto '=https' --tlsv1.3 -sSf | sh


root@vps:~# curl --proto '=https' --tlsv1.3 -sSf | sh
info: downloading installer

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:


This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:


This can be modified with the CARGO_HOME environment variable.

The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:


This path will then be added to your PATH environment variable by
modifying the profile files located at:


You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:

   default host triple: x86_64-unknown-linux-gnu
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
info: profile set to 'default'
info: default host triple is x86_64-unknown-linux-gnu

Run the below command to add the Rust toolchain directory to the PATH environment variable,

source "$HOME/.cargo/env"

Verify the Installation

Verify the Rust installation by requesting the version,

rustc --version


root@vps:~# rustc --version
rustc 1.71.1 (eb26296b5 2023-08-03)

Installing a Compiler

First, update the Apt package index using below command,

apt update

apt upgrade 

Once the upgrades are complete, install the build-essential package using the below command,

apt install build-essential

Creating, Compiling, and Running a Test Program, Start by creating some directories to store the test script,

mkdir ~/rustprojects
cd ~/rustprojects
mkdir testdir
cd testdir

Create a file in testdir to store your Rust code,


Note: You need to use the .rs extension for all your Rust programs.

Add the following code into and save the file,

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

Compile the code using the rustc command,


Run the resulting executable,



root@vps:~/rustprojects/testdir# ./test
Congratulations! You have installed your Rust program and it works.

Use the below command to update the rustup,

rustup update


root@vps:~/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.71.1 (eb26296b5 2023-08-03)

info: cleaning up downloads & tmp directories

Done, you’ve installed and tested out Rust on Ubuntu 18.04.