Guides 11792 Published by

Learn how to upgrade an outdated CMake on CentOS 9 Stream by adding Kitware’s official RPM repository, importing its GPG key, and installing the latest stable release with dnf. The guide walks through creating a custom repo file that points directly to the latest builds, explains why the default 3.10 is insufficient for modern libraries, and offers an optional quick fallback using EPEL. It also includes steps to verify the installation, clean any caching issues, and check for toolchain path conflicts before building your project. In short, the post gives a straightforward, no‑nonsense method to get CMake 3.25 or newer on CentOS 9 so you can compile modern projects without hitting syntax errors.



Install CMake on CentOS 9 Stream: A No‑Nonsense Guide

If you’re trying to compile a project that depends on CMake but your machine only has the stock CentOS 9 packages, you’ll find the official repo version is too old (3.10). In this post I’ll walk you through installing the latest release from Kitware’s RPMs, plus a quick fallback with dnf if you’re in a hurry.

Why the stock repo falls short

CentOS 9 ships CMake 3.10.4. Most modern libraries require at least 3.15, and some even need features that only appear in 3.22+. I’ve seen developers hit snags after pulling a pull request that uses find_package(OpenCV REQUIRED) with version constraints; the build aborts right away because the old CMake can’t parse it.

Step 1: Add Kitware’s official repository
sudo dnf install -y wget gnupg
wget https://cmake.org/files/v3.25/Kitware-archive-keyring.gpg
sudo rpm --import Kitware-archive-keyring.gpg

Why import the key?

Without it, dnf will refuse to trust packages from an unknown source and you’ll get a cryptic “signature verification failed” error.

Create the repo file:

cat <<EOF | sudo tee /etc/yum.repos.d/kitware.repo
[cmake]
name=Kitware RPM Repository for CMake
baseurl=https://download.cmake.org/release/linux-centos-9/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/Kitware-archive-keyring.gpg
EOF

Why the custom repo URL?

The Kitware repo hosts the latest stable RPMs for each CentOS major. Pointing directly to it skips the lag of waiting for a new distro release.

Step 2: Install CMake
sudo dnf install -y cmake

You’ll see something like:

Installed: cmake-3.25.0-1.el9.x86_64

That’s the current stable build—good for most open‑source projects.

Step 3 (optional): Verify the version
cmake --version
# output: cmake version 3.25.0

If the number doesn’t match, you probably hit a caching issue; try sudo dnf clean all and reinstall.

Quick fallback: Use dnf install cmake from CentOS 9

If you just want something that works without external repos:

sudo dnf install -y epel-release
sudo dnf update -y
sudo dnf install -y cmake

This pulls the EPEL build (usually 3.20+). It’s not the newest, but it will compile most code you’ll run today.

Why this matters

You’ve probably been stuck at a “CMakeLists.txt: error: unknown command” after a quick apt install cmake on Ubuntu. The same frustration hits on CentOS when the default package is ancient. Installing the Kitware RPM gives you a fresh, maintained binary that knows how to interpret modern CMake syntax and handles toolchain files correctly.

Quick sanity check before building

If your project still fails after upgrading CMake, double‑check:

1. Cache issues – run cmake --build . --clean-targets or delete the CMakeCache.txt.
2. Toolchain file paths – older projects sometimes hard‑code /usr/bin/cmake. Make sure your environment points to the new binary.

That’s it. No extra dependencies, no confusing options. Just a fresh CMake that lets you compile your code without fighting the OS.