How to Install Rust on Fedora 40 or 39

Rust is a modern systems programming language designed for performance, safety, and concurrency. Its growing popularity is due to its unique features and benefits, especially on a Fedora system. Here’s what you need to know:

  • Memory Safety Without Garbage Collection: Rust’s ownership system ensures memory safety, preventing common bugs like null pointer dereferencing and buffer overflows.
  • High Performance: Comparable to C and C++, Rust delivers the speed needed for system-level programming.
  • Concurrency Without Data Races: Rust’s concurrency model prevents data races at compile time, making concurrent programming safer.
  • Rich Type System and Pattern Matching: These features enable more expressive and safer code.
  • Cargo Package Manager: Cargo simplifies managing dependencies, building, and testing Rust projects.
  • Strong Community and Ecosystem: Extensive libraries (crates) and active community support make development faster and more enjoyable.

For Fedora users, installing and using Rust is straightforward with the default Appstream or RustUp installer script; let’s get started.

Method 1: Install Rust via Default Appstream

Update Fedora Packages Before Rust Installation

To begin, it’s crucial to start with an updated system. Updating your Fedora ensures that all packages, including dependencies required for Rust, are current. This step minimizes potential conflicts and ensures a smoother installation process.

Execute the following command in your terminal to update the packages:

sudo dnf upgrade --refresh

This command refreshes your repository cache and upgrades all your system’s packages to their latest versions.

Install Rust via DNF Command

Once your system is up to date, you can install Rust. Fedora’s package manager, DNF, allows for a straightforward installation of Rust.

In your terminal, execute the following command:

sudo dnf install rust cargo

This command installs several key components of the Rust programming environment:

  • rustc: The Rust compiler, essential for converting your Rust code into executable binaries.
  • Standard Library: Provides a collection of standard functionalities and types, crucial for Rust programming.
  • GDB Support: Integrates with the GNU Debugger, enhancing the debugging experience for Rust programs.
  • rustdoc: A documentation generator that helps you create documentation for your Rust code.
  • Cargo: Rust’s package manager and build system, streamlining the process of managing dependencies and building your Rust projects.

Executing this command equips your Fedora system with all the necessary tools to start developing in Rust, ensuring a comprehensive and efficient programming setup. For another installation method, check out the next section, which uses the Rustup script to install Rust on Fedora Linux.

Method 2: Install Rust via RustUp

Update Fedora Packages

Begin by ensuring your Fedora system is fully updated. This step is crucial as it prepares the system with the latest updates and patches, reducing the risk of compatibility issues during Rust installation.

Execute the command below in your terminal:

sudo dnf upgrade --refresh

This command will refresh the system’s package database and upgrade all installed packages to their most recent versions.

Install Specific Packages

Before installing Rust, it’s necessary to install certain prerequisite packages. These packages are essential for successfully installing and operating Rust on your Fedora system. Run the following command:

sudo dnf install curl dnf-plugins-core cmake gcc clang make -y

This command installs various tools and compilers, including:

  • curl: A tool for transferring data with URL syntax, essential for downloading files.
  • dnf-plugins-core: Enhances DNF’s functionality.
  • cmake: A cross-platform build system.
  • gcc: The GNU Compiler Collection, a standard compiler for C programming.
  • clang: A compiler for C, C++, and Objective-C.
  • make: A build automation tool.

These tools collectively ensure your system is fully equipped to handle the Rust installation process.

Install Rust via RustUp Script

With the necessary packages in place, download and run the Rust installation script. The RustUp script is a convenient and reliable method for installing Rust.

Use the following command:

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

This command fetches the RustUp script securely and initiates the installation. During the installation process, you will be prompted with instructions.

Follow these prompts to complete the setup.

The installation time can vary from 1 to 5 minutes, depending on your server’s internet connection and hardware capabilities.

After the installation, activate the Rust environment in your current shell with the following command:

source ~/.cargo/env

This command configures your shell environment to access Rust’s tools and utilities.

To verify the successful installation of Rust, check the installed version:

rustc -V

This command displays the installed version of Rust, confirming that Rust has been successfully installed on your Fedora system.

Additional Commands With Rust

Update Rust on Fedora

DNF Update Command for Rust

Regularly updating Rust ensures you have the latest features and security patches. For Rust installations via Fedora’s appstream, use the DNF package manager. This command not only updates Rust but also checks and updates all Fedora packages:

sudo dnf upgrade --refresh

RustUp Update Command for Rust

For Rust installations via RustUp, updating is a streamlined process. RustUp directly communicates with the official Rust source to fetch updates. Run the following command in your terminal to update Rust:

rustup update

After updating, activate the Rust environment in your current shell for the updates to take effect:

source ~/.cargo/env

To verify the update, you can check the installed version of Rust:

rustc -V

Remove Rust (Uninstall)

DNF Remove Command for Rust

The process is straightforward if you need to uninstall Rust installed via Fedora’s DNF. This command removes Rust along with its package manager, Cargo:

sudo dnf remove rust cargo

RustUp Remove Command for Rust

For installations done through RustUp, Rust provides an efficient uninstallation process. This command cleanly removes Rust and its associated files from your Fedora system:

rustup self uninstall

Upon executing this command, you’ll receive confirmation that Rust has been successfully removed from your system.

Conclusion

Wrapping up and setting up Rust on Fedora 40 or 39 Linux is a clear-cut task, and following this guide should make the process smooth for you. From updating your Fedora system to installing Rust through the default appstream or the RustUp script, we’ve covered the essentials to get you up and running. This guide also detailed how to keep Rust updated and the straightforward steps to uninstall it if necessary. With Rust now at your fingertips, you’re well-equipped to tackle projects that demand safety, speed, and reliability. Remember, regular updates are crucial to maintaining Rust’s efficiency and security. Happy coding!

2 thoughts on “How to Install Rust on Fedora 40 or 39”

  1. Congratulations for the excellent website and useful guides. For install Rust+cargo I use the default script: curl –proto ‘=https’ –tlsv1.2 -sSf https://sh.rustup.rs | sh. Alternatively in Fedora i use in the terminal:

    # Rust
    sudo dnf in -y rustup
    rustup-init -y
    # Completions for Fish – For other shell see: https://rust-lang.github.io/rustup/installation/index.html
    mkdir -p ~/.config/fish/completions && rustup completions fish > ~/.config/fish/completions/rustup.fish

    Reply
    • Thanks for the feedback and the alternative installation methods! Both the rustup.rs script and the DNF approach are great options. I appreciate you sharing the Fish shell completions tip as well. It’s always helpful to have multiple ways to set up Rust on Fedora. Thanks again for contributing!

      Reply

Leave a Comment