Skip to main content

Introduction to Installing Rust on Linux Mint

Rust is a powerful systems programming language that focuses on performance, reliability, and safe concurrency. If you are a Linux Mint user, this tutorial will guide you through the step-by-step process of installing Rust on your system.

Please note that Rust installation requires an active internet connection, and it may take some time to complete. So let's get started!

Step 1: Update Package Manager

Before installing Rust, it's always a good practice to ensure that your package manager and system are up to date. Open your terminal and execute the following command:

sudo apt update

This will update the package lists for upgrades and new installations.

Step 2: Install Rust

To install Rust on Linux Mint, we will use rustup, the official installer for Rust. Rustup installs Rust and its associated tools, including the package manager cargo.

To begin the installation, open your terminal and execute the following command:

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

This command downloads a script and runs it, which will guide you through the installation process. You will be prompted to proceed, and the installation will begin.

Step 3: Configure the Rust Environment

After the installation is complete, you will be asked to configure the Rust environment. Press 1 and hit Enter to proceed with the default installation.

Rustup will add the necessary environment variables to your ~/.profile file, which will be sourced automatically when you start a new terminal session.

To apply the changes made to ~/.profile without having to logout and login again, execute the following command:

source ~/.profile

Step 4: Verify the Rust Installation

To ensure that Rust has been correctly installed on your Linux Mint system, you can verify the installation by executing the following command:

rustc --version

If the installation was successful, this command will display the installed version of Rust. For example:

rustc 1.58.0 (unknown-linux-gnu)

Step 5: Update Rust Toolchain

It is always recommended to keep your Rust toolchain up to date. To update the Rust compiler and associated tools, you can execute the following command:

rustup update

This command will check for updates and install them if available.

Step 6: Usage Examples

Now that you have Rust installed, let's take a quick look at some usage examples.

Example 1: Compile a Rust Program

Create a new file called hello.rs and open it in a text editor:

nano hello.rs

Add the following code to the file:

fn main() {
println!("Hello, world!");
}

Save the file and exit the text editor.

To compile the Rust program, execute the following command:

rustc hello.rs

This will generate an executable file named hello in the same directory. To run the program, use the following command:

./hello

You should see the output:

Hello, world!

Example 2: Create a New Rust Project with Cargo

Cargo is the package manager and build tool for Rust. It simplifies the process of managing dependencies and building projects.

To create a new Rust project, execute the following command:

cargo new myproject

This will create a new directory named myproject with a basic project structure.

Change into the project directory:

cd myproject

To build and run the project, execute the following command:

cargo run

You should see the output:

Hello, world!

Conclusion

Congratulations! You have successfully installed Rust on your Linux Mint system. We covered the installation process using rustup, configuring the environment, verifying the installation, updating the toolchain, and even explored some usage examples.

Now you are ready to start your Rust programming journey. Have fun exploring the powerful features and building robust applications with Rust!