Rust is a systems programming language focused on safety, speed, and concurrency. On RHEL 8, the recommended way to install Rust is through rustup, the official Rust toolchain installer, which lets you manage multiple Rust versions and cross-compilation targets from a single tool. This approach keeps your Rust installation self-contained under your home directory and does not interfere with system packages. In this tutorial you will install Rust and Cargo on RHEL 8, write and run a simple binary, and learn how to manage your toolchain going forward.
Prerequisites
- A RHEL 8 server or workstation with a non-root sudo user
- EPEL 8 repository enabled (
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm) curlandgccinstalled (dnf install -y curl gcc)- Internet access to reach
sh.rustup.rs
Step 1 — Download and Run the rustup Installer
The official installer script handles everything: downloading the toolchain, setting up Cargo’s binary directory, and configuring your shell profile.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
When prompted, choose option 1 (Proceed with standard installation). The installer places the Rust toolchain under ~/.rustup and Cargo’s binaries under ~/.cargo/bin.
Step 2 — Activate the Cargo Environment
The installer adds a line to ~/.bashrc (or ~/.bash_profile), but you need to source it for the current shell session.
source $HOME/.cargo/env
Verify both tools are available:
rustc --version
cargo --version
You should see output similar to rustc 1.78.0 (9b00956e5 2024-04-29) and cargo 1.78.0.
Step 3 — Create and Run a New Cargo Project
Cargo is Rust’s build tool and package manager. Create a new binary project with cargo new.
cargo new myprog
cd myprog
The generated src/main.rs already contains a Hello World program. Open it to inspect or edit:
cat src/main.rs
Run it in development mode (compiles and executes in one step):
cargo run
You will see Hello, world! printed to the terminal.
Step 4 — Build a Release Binary
Development builds include debug symbols and skip many optimisations. For production or distribution, compile with the --release flag.
cargo build --release
The optimised binary is placed at target/release/myprog. Run it directly:
./target/release/myprog
Step 5 — Install CLI Tools from crates.io
Cargo can install binaries published to crates.io. Two popular tools useful on any Linux system are ripgrep (fast grep replacement) and bat (cat with syntax highlighting).
cargo install ripgrep bat
Both binaries are placed in ~/.cargo/bin, which is already in your PATH. Test them:
rg --version
bat --version
Step 6 — Update the Rust Toolchain
Rust releases a new stable version every six weeks. Update your toolchain with a single command:
rustup update
To update all installed Cargo binaries at once, install the cargo-update utility:
cargo install cargo-update
cargo install-update -a
You can also install additional components such as the Rust formatter and linter:
rustup component add rustfmt clippy
Conclusion
You have installed Rust and Cargo on RHEL 8 using rustup, confirmed both tools are working, created and built a binary project, installed third-party CLI tools from crates.io, and learned how to keep your toolchain up to date. Rustup makes it straightforward to manage Rust versions independently of the system package manager, keeping your environment clean and reproducible. From here you can explore Rust’s rich ecosystem of libraries (called crates) through crates.io and the official documentation at doc.rust-lang.org.
Next steps: How to Install Ruby with rbenv on RHEL 8, How to Install .NET SDK and Runtime on RHEL 8, and How to Install Deno on RHEL 8.