Install CMake on Rocky Linux 9 (EL9) and 8 (EL8) – The Quick‑and‑Dirty Guide
You’ll learn how to get the latest CMake up and running on both EL8 and EL9 with minimal fuss, plus a few tricks for when the default repos bite back.
Why the default repo is usually a no‑go
Rocky Linux ships with a 3.21 or older build of CMake in its base repositories. If you’re trying to compile modern libraries (think OpenCV 4.8 or Qt 6) this version will give you headaches. The package is locked to the distro’s release cycle, and there are no “update me” hooks for newer releases.
Pulling the newest CMake from AppStream on EL9
On Rocky 9 the AppStream channel has a 3.27 build that keeps up with upstream. It’s a one‑liner:
sudo dnf install cmake
The dnf resolver automatically pulls in the AppStream version, which is newer than the legacy repo. If you’re already on EL8 and just typed dnf install cmake, you’ll end up with 3.21 again. The trick is to explicitly ask for the AppStream stream:
sudo dnf module enable cmake:devel sudo dnf install cmake
The module system lets you lock in a specific major release, and cmake:devel points to the latest development branch.
Installing CMake on EL8 via EPEL
EL8 lacks AppStream’s modern CMake, but EPEL supplies a 3.23 build that is more than enough for most projects. First enable EPEL:
sudo dnf install epel-release
Then grab CMake:
sudo dnf install cmake
If you want an even newer release (say 3.27) you’ll need to compile from source, because the EPEL package lags behind upstream.
Compiling CMake yourself when the repo is stuck
When you truly need a bleeding‑edge version—maybe your project requires a feature added in CMake 3.28—you can build it from source. The steps are:
1. Get the latest tarball
Download it straight from the official site. I once had to do this for a custom firmware build that required CMake’s new -E script features.
wget https://github.com/Kitware/CMake/releases/download/v3.28.0/cmake-3.28.0.tar.gz tar xf cmake-3.28.0.tar.gz cd cmake-3.28.0
2. Install build dependencies
CMake needs a compiler, make, and some dev libs.
sudo dnf groupinstall "Development Tools" sudo dnf install zlib-devel libffi-devel
3. Configure with a prefix you control
Don’t clutter the system PATH—install it to /opt/cmake-3.28.
./bootstrap --prefix=/opt/cmake-3.28
4. Compile and install
This is where you burn CPU cycles but also confirm everything compiles on your machine.
make -j$(nproc) sudo make install
5. Make the new CMake visible
Add /opt/cmake-3.28/bin to your PATH, or create a symlink.
echo 'export PATH=/opt/cmake-3.28/bin:$PATH' >> ~/.bash_profile source ~/.bash_profile
Now cmake --version should report 3.28.x, and you’re good to go.
Checking your installation
A quick sanity check:
cmake --version
You should see the version number you just installed. If it still shows the old 3.21 from the base repo, double‑check that your PATH points to the newer binary first, or that you enabled the right module.
Common hiccups and how I dealt with them
- “Could not find zlib” – On EL8 you need zlib-devel.
- AppStream modules stale – Run sudo dnf clean all before re‑installing.
- Permissions error during make install – Use sudo, but avoid installing to /usr/local if you don’t want to clash with the distro’s package manager.
If a tool feels bloated, feel free to skip it. For CMake, the source route is lightweight enough once you’ve got the dependencies sorted.