Rust is a modern programming language known for its performance, reliability, and memory safety. It is designed to ensure safe concurrency and prevent segmentation faults, making it ideal for system programming, web assembly, and other performance-critical applications. Rust’s unique ownership system guarantees memory safety without needing a garbage collector, and its powerful type system and comprehensive standard library make it suitable for a wide range of programming tasks.
To install Rust on Linux Mint 22, 21, or 20, the recommended method is to use rustup, the official installer and version manager for Rust. This method ensures you always have the latest version of Rust. This guide will also demonstrate how to quickly test your installation by creating a simple Rust application and provide maintenance tips such as updating and removing Rust.
Update Linux Mint Before Rust Installation
To ensure a smooth installation of Rust, start by updating your Linux Mint system. This process refreshes your system’s package list and upgrades existing packages to their latest versions.
Open your command terminal and execute the following commands:
sudo apt update
sudo apt upgrade
These commands first update the package list and then upgrade the packages, ensuring your system is current and secure.
Install Initial Packages for Rust Installation
Specific prerequisite packages are required before installing Rust. These packages include curl for downloading the installation script, build-essential for compiling software, and gcc and make for managing dependencies and builds.
Install these packages with the following command:
sudo apt install curl build-essential gcc make -y
This command installs all necessary packages, preparing your system for the Rust installation.
Proceed with Terminal Command to Install Rust via RustUp
With the prerequisites, the next step is downloading and running the Rust installation script.
Use curl to fetch the script securely via HTTPS:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
After running this command, you’ll see an output prompting you to choose the installation type. For most users, the default installation suffices. To proceed, type “1” and press Enter.
The installation process varies in duration, typically 1 to 5 minutes, depending on your internet speed and hardware capabilities.
Once installed, activate the Rust environment for your current shell. This step is crucial as it enables Rust commands in your terminal.
Run the following command:
source "$HOME/.cargo/env"
This command activates the Rust environment, allowing you to use Rust immediately.
Verifying Rust Installation
To confirm that Rust is installed correctly, check the installed version with:
rustc -V
If this command displays the Rust version, it confirms a successful installation. If you encounter any issues or the version doesn’t display, recheck the previous steps, especially the environment activation step, to ensure everything is set up correctly.
Create Rust Sample Project Application
Setting Up a Workspace for Rust Projects
After installing Rust on Linux Mint, it’s vital to validate its functionality. A practical approach is to create a test application. Start by establishing a dedicated workspace for your Rust projects. This workspace organizes your development projects and ensures all files are stored systematically.
Create the workspace directory with the following command:
mkdir ~/rust-projects
This command creates a new directory named rust-projects
in your home directory, dedicated to housing your Rust projects.
Creating a “Hello World” Application in Rust
Navigate to your new workspace and begin crafting your first Rust application:
cd rust-projects && nano helloworld.rs
This command changes your current directory to rust-projects and opens a new file, helloworld.rs, in the nano text editor. Here, you will write your test application.
In the nano editor, enter the following Rust code for a simple “Hello World” program:
fn main() {
println!("Hello World, this is a test provided by LinuxCapable.com");
}
This Rust program, when executed, will print the specified message to the console.
Save and exit the nano editor using “CTRL+O” to write the changes and “CTRL+X” to exit.
Compiling the Rust Application
Compile the “Hello World” application with:
rustc helloworld.rs
This command compiles the Rust source file helloworld.rs into an executable. After successful compilation, you should see a new executable file in your directory.
To confirm the creation of the executable, list the contents of the current directory with:
ls
Executing the Compiled Rust Application
Finally, execute your newly created “Hello World” application with the following command:
./helloworld
Running this command should display the message from your Rust application, confirming that Rust is installed correctly and is ready for further development projects.
Additional Commands For Rust
Update Rust via RUSTUP Command
Rust’s built-in updater, rustup, simplifies keeping your installation current. To update Rust on Linux Mint, open your terminal and run the following command:
rustup update
This command checks for any available updates for Rust and applies them, ensuring your Rust environment is up-to-date with the latest features and security patches.
Remove Rust via RUSTUP Command
If Rust is no longer required on your system, it can be uninstalled cleanly using the rustup tool. To remove Rust from your Linux Mint system, execute this command in your terminal:
rustup self uninstall
This command initiates the Rust uninstallation process, effectively removing it from your system. Upon successful completion, a confirmation message indicates that Rust has been completely uninstalled from your Linux Mint system.
Conclusion
With Rust successfully installed on your Linux Mint system using rustup
, you can take full advantage of its powerful features and safety guarantees. Regularly updating Rust ensures you have the latest features and security updates, while proper maintenance helps keep your development environment clean. By creating and running a test application, you can verify your installation and start exploring Rust’s capabilities. Enjoy the reliability and performance that Rust brings to your development projects.
Thanks for this clear instruction and easy install method. Linux all the way!