Rust is a systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety. With its growing popularity for performance-critical applications, learning to install and use Rust can be a valuable addition to your programming toolkit. This guide will walk you through the steps to install Rust on Ubuntu 24.04 LTS.
Why Rust?
Rust’s memory safety guarantees without needing a garbage collector make it a unique and powerful language for various applications, from web development to embedded systems. It’s designed to provide better memory safety while maintaining high performance, making it a favorite among developers.
Prerequisites
Before starting the installation process, ensure you have:
- A system running Ubuntu 24.04 LTS.
- Sudo privileges.
Step-by-Step Installation Guide
Step 1: Update Your System
First, update your package index to ensure you have the latest information on available packages:
$ sudo apt update
$ sudo apt upgrade -y
Step 2: Install Dependencies
Install the necessary dependencies that Rust needs to compile code and manage packages:
$ sudo apt install -y build-essential curl
Step 3: Install Rust Using rustup
The recommended way to install Rust is using rustup
, a toolchain installer for Rust. It installs Rust and manages updates and versions.
- Download and run the rustup installation script:
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
-
Follow the on-screen instructions: The script will prompt you to proceed with the installation. Press
1
to proceed with the default installation. - Configure your current shell: After installation, you need to configure your current shell to use the Rust environment. This can be done by running:
$ source $HOME/.cargo/env
Step 4: Verify the Installation
To confirm that Rust is installed correctly, you can check the installed version:
$ rustc --version
You should see output similar to:
$ rustc 1.78.0 (9b00957e5 2024-04-29)
Step 5: Update Rust
Rust is regularly updated with new features, improvements, and bug fixes. To ensure you have the latest version, you can update Rust using rustup:
$ rustup update
Step 6: Install and Use Cargo
Cargo is Rust’s package manager and build system. It is installed automatically with Rust. You can verify the Cargo installation by checking its version:
$ cargo --version
Step 7: Create and Run a Simple Rust Program
Now that Rust and Cargo are installed, you can create a simple Rust project to test your setup.
- Create a new project:
$ cargo new hello_world
$ cd hello_world
This command creates a new directory named hello_world
with a simple Rust project structure.
- Build the project:
$ cargo build
- Run the project:
$ cargo run
You should see the output:
Hello, world!
Conclusion
Congratulations! You have successfully installed the Rust programming language on your Ubuntu 24.04 LTS system. You are now ready to start exploring Rust’s powerful features and write safe, concurrent, and fast code. For more information on using Rust, check out the official Rust documentation.
Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.