Support Online
Skip to main content

Installing Rust: Step-by-Step Guide for Ubuntu 20.04 and 22.04

Rust is a modern systems programming language that combines memory security and high performance.
In this guide, you will install Rust on Ubuntu, prepare the compilation environment, and run your first test program.

What Will You Learn in This Guide?

  • What is the Rust programming language used for?
  • How to install Rust in Ubuntu
  • Tools required for compilation
  • Writing and running the first Rust program
  • Rust update and removal steps

What is Rust?

Rust is a programming language that provides safe memory management at the compilation stage.
It is widely used in browser engines, game engines and system software.


Prerequisites

  • Ubuntu 20.04 or 22.04
  • User with sudo privilege
  • Internet connection

1. Installing Rust with rustup

The safest way to install Rust on Ubuntu is the rustup tool.
This tool centrally manages Rust versions.

curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh
  • This command downloads the Rust installer and installs the stable version. Confirm the default option by typing 1 on the setup screen.

2. Loading Environment Variables

  1. After installation, PATH must be updated for Rust commands to work.

source $HOME/.cargo/env
  • This command activates Rust and Cargo tools.

3. Verifying the Installation

  1. Verify that Rust is installed correctly by version checking.

rustc --version
  • This command prints the installed Rust version to the screen.

4. Installing Compiler Dependencies

  1. Rust codes need a system linker when compiling.
  • These tools are provided with the build-essential package.

sudo apt update && sudo apt upgrade -y
  • This command updates system packages.


sudo apt install build-essential -y
  • This command installs gcc and the necessary build tools.

5. Running Your First Rust Program

  1. Let's create a simple program to test that the installation was successful.

mkdir ~/rust_projeleri && cd ~/rust_projeleri
nano test.rs
  • These commands create the project directory and open the Rust file.

Add the following code into the file:


fn main() {
println!("Tebrikler! Rust programınız başarıyla çalışıyor.");
}
  • This code prints a message on the screen.

  1. Compilation

rustc test.rs
  • This command converts Rust code into executable file.

  1. Operation

./test
  • This command runs the compiled Rust program.

Frequently Asked Questions (FAQ)

1. How do I update Rust? You can use the rustup update command to update the Rust version.

2. What is Cargo? Cargo is Rust's package manager and build system. It makes dependency management automatic.

3. How do I completely uninstall Rust? The following command deletes all Rust components:


rustup self uninstall

Result

Installing Rust on Ubuntu is fast and hassle-free. Thanks to rustup, version management and updates become easier.

You can immediately start developing powerful and secure systems by running your high-performance Rust projects on the GenixNode infrastructure 🚀