Back to blog

Published on Thursday, December 26, 2024

How to install Rust on Linux

How to install Rust on Linux

Step 1: Update Your Package Manager

First, it's a good idea to update your package manager to ensure you have the latest package lists:

sudo apt update

Step 2: Install Required Dependencies

Rust requires some development tools like curl and build-essential. You can install them using the following command:

sudo apt install curl build-essential

Step 3: Install Rust Using rustup

Rust is best installed and managed using rustup, the official installer for Rust. To install it, run:

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

You'll be prompted to confirm the installation and customize your setup. Press 1 to proceed with the default installation.

Step 4: Configure Your Environment

Once the installation is complete, you'll need to configure your shell to recognize the Rust toolchain. Add the following line to your shell profile (e.g., .bashrc, .zshrc, .profile):

# Rust Path
export RUSTUP_HOME=~/.rustup
export CARGO_HOME=~/.cargo
export PATH=$PATH:~/.cargo/bin

Then, reload your shell:

source ~/.bashrc

Step 5: Verify the Installation

To confirm that Rust is installed correctly, check the version by running:

rustc --version

If everything is set up properly, you'll see the installed version of Rust.

Step 6 (Optional): Update Rust

Rust is frequently updated, so it's important to keep your toolchain up-to-date. You can update Rust using:

rustup update

Conclusion

Congratulations! You've successfully installed Rust on your Linux system. You can now start building fast, reliable, and efficient software. Whether you're new to Rust or an experienced developer, you'll find that this language offers a powerful toolset for system-level programming.