Rust is a systems programming language that delivers memory safety without a garbage collector, making it an excellent choice for writing reliable system administration tools on RHEL 9. The official installer, rustup, manages toolchain versions independently of the operating system packages and is the recommended installation method. This tutorial covers installing Rust via rustup, building a practical memory-reporting tool from scratch, and installing popular Rust-based system utilities.

Prerequisites

  • RHEL 9 server with a user that has sudo privileges
  • Internet access to reach sh.rustup.rs
  • GCC build toolchain (gcc, make) installed for linking
  • Basic familiarity with the terminal

Step 1 — Install Build Dependencies and Rust via rustup

Rust links against the system C linker, so install the development tools group first, then run the rustup installer.

sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y gcc openssl-devel pkg-config

Download and run the rustup installer. Select option 1 (default installation) at the prompt.

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

Source the environment file so the current shell session can see the Rust binaries:

source $HOME/.cargo/env

To make the environment permanent for all future sessions, add the source line to your shell profile:

echo 'source $HOME/.cargo/env' >> ~/.bashrc

Step 2 — Verify the Toolchain

Confirm that both the compiler and package manager are working correctly.

rustc --version
# rustc 1.78.0 (9b00956e5 2024-04-29)

cargo --version
# cargo 1.78.0 (54d8815d0 2024-03-26)

rustup show

Step 3 — Create a New Binary Project

Cargo, Rust’s build system and package manager, scaffolds a project with the correct directory layout and a starter main.rs.

cargo new mytool --bin
cd mytool

Replace the generated src/main.rs with a tool that reads /proc/meminfo and reports key memory statistics in a human-readable format:

cat > src/main.rs <<'EOF'
use std::collections::HashMap;
use std::fs;

fn main() {
    let content = fs::read_to_string("/proc/meminfo")
        .expect("Failed to read /proc/meminfo");

    let mut stats: HashMap = HashMap::new();
    for line in content.lines() {
        let mut parts = line.splitn(2, ':');
        if let (Some(key), Some(val)) = (parts.next(), parts.next()) {
            let kb: u64 = val.split_whitespace()
                .next()
                .and_then(|v| v.parse().ok())
                .unwrap_or(0);
            stats.insert(key.trim(), kb);
        }
    }

    let total = stats.get("MemTotal").copied().unwrap_or(0);
    let free  = stats.get("MemFree").copied().unwrap_or(0);
    let avail = stats.get("MemAvailable").copied().unwrap_or(0);
    let used  = total.saturating_sub(avail);

    println!("Memory Report");
    println!("-------------");
    println!("Total    : {:>8} MB", total / 1024);
    println!("Used     : {:>8} MB", used  / 1024);
    println!("Free     : {:>8} MB", free  / 1024);
    println!("Available: {:>8} MB", avail / 1024);
}
EOF

Step 4 — Build and Run the Tool

Compile a debug build first for a quick check, then produce an optimised release binary.

# Debug build — fast compile, larger binary
cargo build
./target/debug/mytool

# Release build — optimised and stripped
cargo build --release
./target/release/mytool

# Optionally install system-wide
sudo cp target/release/mytool /usr/local/bin/
mytool

Step 5 — Install Popular Rust System Utilities

cargo install compiles and installs community tools directly from crates.io. These tools are widely used as modern replacements for classic Unix utilities.

# bat — cat with syntax highlighting and line numbers
cargo install bat

# ripgrep — extremely fast grep replacement
cargo install ripgrep

# fd-find — simple, fast alternative to find
cargo install fd-find

# eza — modern replacement for ls with colour and icons
cargo install eza

# Verify installations
bat --version
rg --version
fd --version
eza --version

Cargo places binaries in $HOME/.cargo/bin. Because you sourced $HOME/.cargo/env in Step 1, these are already on your PATH.

Step 6 — Update the Toolchain

Rust follows a six-week release cycle. Keeping the toolchain current is a single command:

rustup update

# Update all installed cargo tools at once
cargo install cargo-update
cargo install-update -a

Conclusion

You have installed Rust via rustup on RHEL 9, verified the compiler and Cargo package manager, built a practical /proc/meminfo reporting tool with a release-optimised binary, and installed a collection of popular Rust-based system utilities. The same cargo install workflow applies to any crate published on crates.io.

Next steps: How to Install Java and Configure JAVA_HOME on RHEL 9, How to Deploy a .NET Application on RHEL 9, and How to Install Go and Build CLI Tools on RHEL 9.