How to Install Rust on Debian 12, 11 or 10

Rust emerges as a frontrunner in modern programming languages, renowned for emphasizing safety, concurrency, and efficiency. For Debian users, integrating Rust can significantly elevate their software development endeavors. This guide is tailored to demonstrate how to install Rust on Debian 12 Bookworm, Debian 11 Bullseye, or Debian 10 Buster, ensuring you harness the full potential of this cutting-edge language.

Salient Features of Rust:

  • Memory Safety: Rust’s ownership system and borrow checker work to guarantee memory safety. These mechanisms operate at compile time, eliminating the need for a garbage collector and ensuring programs are devoid of undefined behavior and data races.
  • Concurrency Mastery: Rust’s fearless concurrency model effectively manages concurrent programming, preventing data races. This model facilitates the safe and efficient execution of parallel code, positioning Rust as a top choice for performance-driven applications.
  • Optimized Performance: Rust’s meticulous design prioritizes performance. Its granular control over system resources allows it to rival the performance metrics of languages like C++.
  • Seamless Interoperability: Rust’s compatibility with other languages, especially C, is commendable. This interoperability enables developers to utilize Rust for performance-critical segments while capitalizing on existing code repositories.
  • Robust Ecosystem: Rust’s ecosystem, enriched with many libraries and tools, continually expands. The package manager, Cargo, streamlines the management of these resources. Furthermore, the Rust community’s proactive and inclusive nature ensures comprehensive documentation, learning materials, and unwavering support.
  • Modern Syntax: Rust’s syntax is modern and expressive, enhancing code readability and writability. Its static typing ensures the compiler identifies numerous errors pre-runtime, creating safer and more maintainable software.

Given Rust’s myriad of advantages, it’s evident that it is a formidable choice for contemporary software development. Whether venturing into system applications, web services, or gaming, Rust equips you with the tools to craft swift, secure, and efficient software solutions.

Install Rust on Debian 12, 11, or 10 via APT PPA

Step 1: 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

Step 2: 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

Step 3: Install Rust via cURL and Bash on Debian

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 the script will be 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
Screenshot of the terminal prompt during Rust installation on Debian Linux.
Captured terminal prompt as Rust begins its installation on Debian Linux.

You will be prompted to choose an installation option during the installation process. Type 1 and hit Enter to proceed with the default installation.

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

Screenshot of successful Rust installation terminal output on Debian Linux.
Terminal confirmation of Rust being successfully installed on a Debian Linux system.

Step 4: Activate Rust Environment on Debian

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

Step 5: 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 on Debian 12, 11 or 10

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.

Step 1: 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

Step 2: 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, and then exit nano by pressing CTRL+X.

Step 3: 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 the compilation process is complete. The directory should now contain both the source file and the compiled executable, as shown in the example output below:

helloworld  helloworld.rs

Step 4: 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 on Debian 12, 11 or 10

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
Screenshot of the terminal process updating Rust on Debian Linux.
A terminal display showcasing the procedure to update Rust on a Debian Linux system.

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

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

rustup self uninstall
Screenshot showcasing the terminal process of removing Rust from Debian Linux.
Terminal display illustrating the steps to remove Rust from a Debian Linux setup.

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

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

Conclusion

This guide demonstrated how to install Rust on Debian Linux systems, including Debian 12 Bookworm, Debian 11 Bullseye, and Debian 10 Buster. If you followed the step-by-step instructions, you should now have a working Rust installation and be able to create, compile, and run Rust applications on your Debian system.

Additionally, we’ve covered some essential commands and tips for managing your Rust installation, such as updating and uninstalling Rust when necessary. By mastering these concepts, you can ensure a smooth and efficient Rust development experience on Debian Linux.

1 thought on “How to Install Rust on Debian 12, 11 or 10”

Leave a Comment