Rust is a systems programming language that guarantees memory safety without a garbage collector, making it an excellent choice for writing reliable, high-performance tools that run directly on RHEL 8. The official installer, rustup, manages toolchain versions independently of the OS package manager, giving you access to the stable, beta, and nightly channels side by side. This tutorial covers installing Rust via rustup, writing a small system-information utility that reads /proc files, using the nix crate for POSIX bindings, producing a stripped release binary, and installing well-known community tools compiled from source. A brief overview of cross-compilation closes the guide.

Prerequisites

  • A RHEL 8 server with a non-root sudo user
  • EPEL 8 repository enabled (dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm)
  • Development tools present: sudo dnf groupinstall "Development Tools"
  • OpenSSL development headers: sudo dnf install openssl-devel
  • Internet access to reach static.rust-lang.org and crates.io

Step 1 — Install Rust with rustup

The rustup installer downloads the stable toolchain, sets up cargo, and configures your shell profile automatically.

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

# Reload the PATH set by rustup
source $HOME/.cargo/env

rustc --version
cargo --version
# Expected: rustc 1.78.x  /  cargo 1.78.x

Step 2 — Create a New Binary Crate

Use cargo new to scaffold a binary project, then add the nix crate to your dependencies for safe POSIX bindings.

cargo new mysystool --bin
cd mysystool

# Add the nix crate for POSIX API access
cargo add nix --features "fs process signal"

# Verify Cargo.toml contains the dependency
grep -A2 '[dependencies]' Cargo.toml

Step 3 — Read System Information from /proc

Replace the contents of src/main.rs with the following program, which reads CPU model and memory information directly from the Linux /proc virtual filesystem.

cat > src/main.rs < String {
    fs::read_to_string(path)
        .unwrap_or_default()
        .lines()
        .find(|l| l.starts_with(key))
        .and_then(|l| l.split(':').nth(1))
        .map(|v| v.trim().to_string())
        .unwrap_or_else(|| "unknown".into())
}

fn main() {
    let cpu  = read_proc("/proc/cpuinfo", "model name");
    let mem  = read_proc("/proc/meminfo", "MemTotal");
    let kern = fs::read_to_string("/proc/version")
                 .unwrap_or_default();
    println!("CPU   : {}", cpu);
    println!("Memory: {}", mem);
    println!("Kernel: {}", kern.trim());
}
RUST

cargo run

Step 4 — Build a Stripped Release Binary

The --release profile enables full compiler optimisations. Stripping the resulting binary with the system strip utility removes symbol tables and reduces file size by 50–70 %.

cargo build --release

# Before strip
ls -lh target/release/mysystool

strip target/release/mysystool

# After strip — significantly smaller
ls -lh target/release/mysystool

# Install system-wide
sudo cp target/release/mysystool /usr/local/bin/mysystool
sudo chmod 0755 /usr/local/bin/mysystool
mysystool

Step 5 — Install Community Tools from crates.io

cargo install downloads, compiles, and places binaries in ~/.cargo/bin. The following command installs three widely used Rust-based replacements for classic UNIX utilities.

# ripgrep  — fast recursive grep replacement
# fd-find  — user-friendly find replacement
# bat      — cat with syntax highlighting
cargo install ripgrep fd-find bat

# Verify
rg --version
fd --version
bat --version

# Optionally install system-wide
sudo install -m 0755 ~/.cargo/bin/{rg,fd,bat} /usr/local/bin/

Step 6 — Cross-Compilation Overview

Rust supports cross-compilation through target triples. Adding a target with rustup and a compatible linker lets you build ARM64 binaries from an x86_64 RHEL 8 host.

# Install the ARM64 target
rustup target add aarch64-unknown-linux-gnu

# Install the cross-linker (from EPEL or cross-compilation toolchain)
sudo dnf install gcc-aarch64-linux-gnu

# Configure the linker for the target in ~/.cargo/config.toml
cat >> ~/.cargo/config.toml << 'EOF'
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
EOF

# Build for ARM64
cargo build --release --target aarch64-unknown-linux-gnu
file target/aarch64-unknown-linux-gnu/release/mysystool
# ELF 64-bit LSB executable, ARM aarch64

Conclusion

You have installed Rust using rustup on RHEL 8, written a system-information tool that reads /proc/cpuinfo and /proc/meminfo, leveraged the nix crate for safe POSIX bindings, produced and stripped an optimised release binary, installed community tools from crates.io, and explored cross-compilation to ARM64. The same workflow scales from small utilities to large, multi-crate workspaces.

Next steps: How to Write Integration Tests for Rust System Tools on RHEL 8, How to Package Rust Binaries as RPMs with cargo-generate-rpm, and How to Use Tokio for Async Networking in Rust on RHEL 8.