You need the latest Rust, but dnf only has last year's version
You cloned a repository from GitHub and ran cargo build. The build failed with error: linker 'cc' not found. Or you got error[E0463]: can't find crate for 'std' even though you installed the rust package. Or the project requires Rust 1.78, and dnf only offers 1.75. Fedora's package manager provides a single version of the compiler locked to the release cycle. Rust development moves faster than the 6-month cadence. You need rustup.
rustup is the official installer. It manages toolchains in your home directory, isolates them from the system, and lets you switch versions per project. It installs cargo, the build tool, and rustc, the compiler. It also handles components like rustfmt, clippy, and rust-analyzer. It never touches /usr/bin or /etc. You can experiment freely. If you mess up, delete the directories and reinstall. Your system remains untouched.
What rustup does that dnf cannot
dnf install rust drops binaries into /usr/bin. That works for a simple script on a server. It fails when you need multiple versions, nightly builds, or project-specific toolchains. rustup stores everything in ~/.rustup and ~/.cargo. Each toolchain version lives in its own directory. You can have stable, beta, nightly, and specific dates installed simultaneously.
rustup also manages components. The system package includes only the compiler and standard library. rustup lets you add rustfmt for formatting, clippy for linting, and rust-src for debugging. You can switch the default toolchain globally or override it for a specific project. The override writes a rust-toolchain.toml file in the project root. Other developers get the right version automatically when they clone the repo.
rustup modifies ~/.bashrc or ~/.zshrc to add ~/.cargo/bin to your PATH. This is user configuration. It is safe. It does not affect other users or system services.
Install rustup and activate the toolchain
Here's how to fetch and run the installer. The script downloads the latest stable toolchain and configures your environment.
# Download the rustup installer script securely over HTTPS
# --proto '=https' enforces HTTPS, --tlsv1.2 sets minimum TLS version
# -sSf flags: silent mode, show errors, fail silently on server errors
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
The installer prompts for confirmation. Press 1 for the default installation. It installs the stable toolchain and updates your shell profile. After it finishes, load the environment variables in your current session.
# Load the cargo environment variables into the current shell session
# This adds ~/.cargo/bin to your PATH so rustc and cargo are found immediately
source $HOME/.cargo/env
Source the env file before you panic. The tools are installed, your shell just doesn't know yet.
Verify the installation
Here's how to confirm the toolchain is active and ready to compile.
# Check the compiler version to confirm the toolchain is active
rustc --version
# Check the package manager version
cargo --version
You should see output like rustc 1.78.0 and cargo 1.78.0. If you see command not found, your shell hasn't sourced the profile. Run source $HOME/.cargo/env again or restart the terminal.
Create a project and verify the build
Here's how to scaffold a new project and run it.
# Create a new binary project named hello-fedora with the standard directory structure
cargo new hello-fedora
# Move into the project directory
cd hello-fedora
# Compile and run the project in one step
cargo run
The project structure contains Cargo.toml for metadata and dependencies, and src/main.rs for the entry point. cargo run compiles the code and executes the binary. You should see Hello, world!.
Run cargo check before cargo build. It's faster and tells you the same errors without the wait.
Manage dependencies and system libraries
Here's how to declare a dependency in the manifest file. Cargo resolves versions automatically based on semantic versioning.
[dependencies]
# Add serde version 1.x with the derive feature enabled
# The derive feature allows automatic implementation of serialization traits
serde = { version = "1", features = ["derive"] }
Some crates bind to C libraries or require build scripts. You need a C compiler and pkg-config on the system. Fedora splits packages into -devel for headers. Install the build tools via dnf.
# Install the C compiler and pkg-config for build scripts
# openssl-devel provides headers for crates that link against OpenSSL
sudo dnf install gcc pkg-config openssl-devel
Here's how to download dependencies and compile the project. Cargo caches dependencies in ~/.cargo/registry to avoid re-downloading.
# Download dependencies and compile the project
# Cargo caches dependencies in ~/.cargo/registry to avoid re-downloading
cargo build
Commit rust-toolchain.toml to version control. It keeps the project reproducible across machines.
Switch toolchains and isolate projects
Here's how to manage multiple toolchains and set overrides.
# Set the stable toolchain as the default for all new projects
rustup default stable
# Install a specific nightly version for experimental features
rustup install nightly-2024-05-01
# Override the toolchain for the current directory only
# This creates a rust-toolchain.toml file in the project root
rustup override set nightly
rustup override writes a rust-toolchain.toml file. This file travels with the project. When you enter the directory, rustup switches to the specified toolchain automatically. This is better than hardcoding versions in Cargo.toml. The override file is the source of truth for the project environment.
Trust rustup override. It keeps the project reproducible.
Keep Rust up to date
Here's how to update your toolchains.
# Update all installed toolchains to their latest versions
# This checks for new stable, beta, and nightly releases
rustup update
rustup update is your weekly check. Run it when you need the latest compiler or security fixes. dnf upgrade --refresh is for system packages. Keep them separate. rustup does not manage system libraries.
Useful Cargo commands
Here's how to use the standard workflow commands.
# Check syntax and types without generating binaries
# This is fast and useful for quick feedback during development
cargo check
# Run the linter to catch common mistakes and improve code style
cargo clippy
# Format source code according to rustfmt rules
cargo fmt
# Run the test suite defined in the project
cargo test
# Build an optimized binary for production use
# The resulting executable lands in target/release/
cargo build --release
cargo check is your best friend during development. It runs type checking without linking. It finishes in seconds. Use it constantly.
Editor support
Here's how to install the language server component for IDE integration.
# Install the language server component for IDE integration
# This provides autocomplete, go-to-definition, and diagnostics
rustup component add rust-analyzer
rust-analyzer is the official language server. It runs as a background process and communicates with your editor. It reads the toolchain from rustup.
For VS Code on Fedora, you can use the Flatpak version.
# Install VS Code via Flatpak if you prefer the containerized version
# Flatpak isolates the editor but rust-analyzer runs in the host PATH
flatpak install flathub com.visualstudio.code
Install the rust-analyzer extension from the VS Code marketplace. The extension reads rust-analyzer from your PATH automatically. It does not bundle its own binary.
Common errors and how to fix them
You will encounter errors. Here's what they mean and how to resolve them.
The cargo build command will refuse to proceed and print error[E0463]: can't find crate for 'std'. This happens when your shell cannot find rustc. Run source $HOME/.cargo/env or restart the terminal.
If you see error: linker 'cc' not found, your system is missing a C compiler. Install gcc via sudo dnf install gcc.
If rustc --version shows an old version, you might have the system package installed alongside rustup. Check which binary is active.
# Check which rustc is active to ensure rustup is taking precedence
which rustc
# Expected output: /home/username/.cargo/bin/rustc
If the output points to /usr/bin/rustc, remove the system package.
# Remove the system rust package to avoid PATH conflicts
sudo dnf remove rust
Check which rustc first. If it points to /usr/bin, you are fighting a PATH war.
When to use rustup versus dnf
Use rustup when you need multiple toolchain versions or the latest stable release immediately. Use dnf install rust when you are writing a simple script on a server and want the compiler managed by the system package manager. Use cargo install when you want to deploy a binary tool from crates.io to your local machine. Use rustup override when a specific project requires a different Rust version than your global default.
Stick to rustup for development. The system package is a trap for version mismatches.