How to Install Rust on Debian 12, 11 or 10 Linux

Rust is a systems programming language known for its performance, reliability, and memory safety. Rust achieves these qualities without a garbage collector, making it ideal for performance-critical code. Its unique ownership system guarantees memory and thread safety, eliminating many bugs at compile time. Rust’s zero-cost abstractions mean you can write high-level code without sacrificing performance. The language also boasts a powerful macro system, a comprehensive package manager (Cargo), and an extensive standard library. These features make Rust an excellent choice for developing everything from low-level system components to high-level web applications.

To install the latest version of Rust on Debian 12, 11, or 10, you can use rustup, the official Rust installer and version manager. This guide will walk you through the installation process and demonstrate how to compile a quick test application to ensure your setup works correctly.

Update Debian Before Rust Installation

Before starting the Rust installation, it’s essential to update your Debian system to ensure all existing packages are up to date. This ensures compatibility and prevents potential issues during the installation process. Run the following command to update your system:

sudo apt update && sudo apt upgrade

Install Initial Required Installation Packages For Rust

Next, you need to install some required packages that will be used during the Rust installation. These packages include essential build tools such as curl, build-essential, gcc, and make. To install these packages, execute the following command:

sudo apt install curl build-essential gcc make

Install Rust via cURL and Bash

With the required packages installed, you can install Rust on Debian via the curl command on your system. The Rust installation script will be downloaded using curl and executed automatically.

Run the following command to download and run the Rust installation script:

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

During the installation process, you will be prompted to choose an installation option. Type 1 and hit Enter to proceed with the default installation.

The installation process can take 1 to 5 minutes, depending on your server’s internet speed and hardware. Once the installation is complete, you will see a confirmation message.

Activate Rust Environment

Next, you must activate the Rust environment for your current shell session. This allows you to use Rust-related commands and tools. To activate the Rust environment, run the following commands:

source ~/.cargo/env

Confirm Rust Installation

Finally, to ensure Rust has been successfully installed on your system, you can check the version of the Rust compiler (rustc). Type the following command and hit Enter to display the Rust compiler version:

rustc -V

Create a Test Rust Application

After installing Rust, it’s essential to test the installation to ensure it’s working correctly. The best way to verify this is by creating a simple test application, like the classic “Hello World” program.

Create a Workspace Directory

First, create a directory that will serve as a workspace for your Rust projects. This helps keep your projects organized and easy to find. Run the following command to create a new directory called rust-projects in your home folder:

mkdir ~/rust-projects

Create a Sample Application in Rust

Next, change to the newly created rust-projects directory and create a new Rust source file called helloworld.rs using a text editor like nano. Run the following command to open the file in Nano:

cd rust-projects && nano helloworld.rs

Now, enter the following Rust code for the “Hello World” test:

fn main() {
    println!("Hello World, this is a test provided by LinuxCapable.com");
}

Save the changes by pressing CTRL+O, then exit nano by pressing CTRL+X.

Compile Rust Test Program

With the source file created, you can now compile the program using the Rust compiler, rustc. Run the following command to compile the helloworld.rs file:

rustc helloworld.rs

This command will create an executable file named helloworld in your current directory after completing the compilation process. The directory should now contain both the source file and the compiled executable, as shown in the example output below:

helloworld  helloworld.rs

Run the Test Application

Finally, to run the “Hello World” application you created using Rust, execute the following command:

./helloworld

You should see the output from the test application, which should look like this:

Hello World, this is a test provided by LinuxCapable.com

If you see the above output, your Rust installation is working correctly, and you can start developing Rust applications on your system.

Additional Commands Rust Commands

This section will cover some useful commands and tips for managing your Rust installation, including updating and uninstalling Rust.

Update Rust on Debian

Keeping your Rust installation up-to-date is essential to ensure you have access to the latest features, bug fixes, and performance improvements. Updating Rust is straightforward and can be done using a single command in your terminal. To update Rust, run the following command:

rustup update

This command will check for available updates and install them automatically. If your Rust installation is already up-to-date, the command will notify you.

Remove (Uninstall) Rust From Debian

You can easily remove it using the tool if you no longer need Rust on your Debian system. To uninstall Rust, run the following command:

rustup self uninstall

This command will remove Rust and its associated components from your system.

Note: This command only uninstalls Rust itself and does not remove any projects, source files, or executables you’ve created using Rust.

Conclusion

With Rust successfully installed on your Debian system using rustup, you can start leveraging its powerful features for your development projects. Compiling a test application confirms that your installation is working correctly. Regularly update Rust through rustup to keep up with the latest features and improvements. Enjoy the performance and reliability that Rust brings to your programming tasks.

Leave a Comment