Sunday, September 25, 2022

How To Set up Rust Programming Language on Debian 11

In this article, we want to teach you How To Set up Rust Programming Language on Debian 11.

Rust is a static multiparadigm, memory-efficient programming language, focused on speed, security, and performance. It is used to develop game engines, file systems, websites and tools, operating systems, browser components, and much more. The Rust Foundation, an independent organization, now manages the open-source codebase.

How To Set up Rust Programming Language on Debian 11

Before you start to set up Rust on Debian 11, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article the Initial Server Setup with Debian 11.

Now follow the steps below to complete this guide.

Install Rust Programming Language on Debian 11

First, you need to update and upgrade your APT repository list with the following command:

sudo apt update && sudo apt upgrade -y

Then, you need to install the required packages on your server with the command below:

sudo apt install curl build-essential gcc make -y

Now you can install Rust on Debian 11, by running the Rust installer script:

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

You will get the following output. Type 1 and press enter to continue your installation.

Output
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
>1

When your Rust installation on Debian 11 is completed, you will get the following output:

Output
Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).

To configure your current shell, run:
source $HOME/.cargo/env

Now you need to activate the Rust environment for your current shell with the following commands:

# source ~/.profile
# source ~/.cargo/env

Verify your Rust installation on Debian 11 by checking its version:

rustc -V
Output
rustc 1.59.0 (9d1b2106e 2022-02-23)

How To Use Rust Programming Language

At this point, we want to teach you how to use the Rust programming language by creating a sample project Hello world!.

First, you need to create a Rust project directory with the following command:

mkdir ~/rust-projects

Then, switch to your Rust programming directory:

cd rust-projects

Now use your favorite text editor to create your sample application, here we use vi:

vi helloworld.rs

Add the following content to the file:

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

When you are done save and close the file.

Next, you need to compile the program with the following command:

rustc helloworld.rs

This will create an executable application.

Run the application with the command below:

./helloworld

In your output you will see:

Output
Hello World, this is a test provided by orcacore.com

To update your Rust programming language, you can use the following command:

rustup update

If you don’t want to use Rust, you can easily uninstall it from your Debian 11 with the following command:

rustup self uninstall

Conclusion

At this point, you learn to Set up Rust Programming Language on Debian 11. Also, you learn basic usage of Rust by creating a sample project.

Hope you enjoy it.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular