Sling Academy
Home/Rust/How to setup/ update Rust on Ubuntu

How to setup/ update Rust on Ubuntu

Last updated: January 02, 2025

Setting up and updating Rust on Ubuntu is a straightforward process thanks to the Rust programming language's robust tooling. In this tutorial, we'll delve into the step-by-step installation process, and learn how you can keep your Rust installation up to date with the latest releases.

Installing Rust with Rustup

The recommended way to install Rust is via rustup, a toolchain installer specifically for the Rust programming language. It manages downloads, updates, and the installation of Rust compiler versions conveniently.

First, let's install the necessary dependencies to make Rustup work seamlessly:

sudo apt update
sudo apt install build-essential curl

Now we're ready to install Rust using rustup:

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

You will be guided through a few prompts asking for your confirmation to proceed with the installation.

After the installation, ensure Rust is set up by running:

source $HOME/.cargo/env

To verify that Rust is correctly installed, execute:

rustc --version

This command will display the installed version of Rust.

Updating Rust

As Rust is updated frequently with new features and optimizations, it's important to keep your installation up-to-date. Rustup simplifies this process.

To update your Rust installation, use the following command:

rustup update

This command will automatically fetch the latest versions of the necessary components and update your local Rust installation.

After the update, it's good practice to verify the update by checking the Rust version again:

rustc --version

Installing Specific Toolchains and Components

Rustup allows the installation of multiple toolchains (such as stable, beta, and nightly versions), which is ideal for testing features or deploying applications with different version requirements.

To install an alternate toolchain, similar to how we update Rust:

rustup toolchain install nightly

To switch to the newly installed toolchain:

rustup default nightly

To list installed toolchains and confirm the default version:

rustup toolchain list

Cleaning Up Disk Space

Rustup can sometimes occupy a lot of disk space due to the installation of various versions and build artifacts. You can minimize disk usage using the cleanup command:

rustup component remove rust-src rust-docs

This command ensures unnecessary files are removed, conserving disk space.

Troubleshooting

If you encounter problems, starting from a clean Rust environment can often resolve unexplained issues. To remove Rust completely:

rustup self uninstall

This command will remove all Rust toolchains, installed components, and the rustup tool itself.

Once removed, you can reinstall Rust using the steps outlined in the installation section.

This comprehensive guide lays the groundwork for a smooth Rust installation and update process on Ubuntu, empowering you to harness the full capabilities of this powerful programming language.

Next Article: Top VS Code extensions for Rust programming language

Previous Article: How to setup/ update Rust on Mac

Series: The basics of Rust

Rust

You May Also Like

  • E0557 in Rust: Feature Has Been Removed or Is Unavailable in the Stable Channel
  • Network Protocol Handling Concurrency in Rust with async/await
  • Using the anyhow and thiserror Crates for Better Rust Error Tests
  • Rust - Investigating partial moves when pattern matching on vector or HashMap elements
  • Rust - Handling nested or hierarchical HashMaps for complex data relationships
  • Rust - Combining multiple HashMaps by merging keys and values
  • Composing Functionality in Rust Through Multiple Trait Bounds
  • E0437 in Rust: Unexpected `#` in macro invocation or attribute
  • Integrating I/O and Networking in Rust’s Async Concurrency
  • E0178 in Rust: Conflicting implementations of the same trait for a type
  • Utilizing a Reactor Pattern in Rust for Event-Driven Architectures
  • Parallelizing CPU-Intensive Work with Rust’s rayon Crate
  • Managing WebSocket Connections in Rust for Real-Time Apps
  • Downloading Files in Rust via HTTP for CLI Tools
  • Mocking Network Calls in Rust Tests with the surf or reqwest Crates
  • Rust - Designing advanced concurrency abstractions using generic channels or locks
  • Managing code expansion in debug builds with heavy usage of generics in Rust
  • Implementing parse-from-string logic for generic numeric types in Rust
  • Rust.- Refining trait bounds at implementation time for more specialized behavior