Many C and C++ builds fail before compilation starts when the project cannot find CMake. The configure step uses CMake to detect compilers, generate Make or Ninja build files, and locate libraries before the real build begins. Install CMake on Rocky Linux with the AppStream package for the lowest-maintenance path; Rocky Linux 10 currently ships the 3.30 series, while Rocky Linux 9 and 8 ship the 3.26 series.
Use the Rocky package unless a project explicitly requires a newer Kitware release. The upstream binary method covers that case without compiling CMake itself, but it uses a dedicated /opt/cmake-upstream prefix and a local update helper so removal stays predictable.
Install CMake on Rocky Linux
Choose a CMake Method on Rocky Linux
The normal package name is cmake, so sudo dnf install cmake is the correct Rocky Linux command. Older yum install cmake examples usually work through DNF compatibility, but use dnf for current Rocky Linux documentation and scripts.
| Method | Source | Version Scope | Updates | Best Fit |
|---|---|---|---|---|
| Rocky package | Rocky AppStream | Rocky 10 currently ships 3.30.x; Rocky 9 and 8 ship 3.26.x | Managed by dnf upgrade | Most development systems, CI runners, and stable build hosts |
| Kitware upstream binary | CMake downloads | Latest non-prerelease Kitware build for x86_64 or aarch64 | Run sudo /usr/local/bin/update-cmake-upstream | Projects that require a newer upstream point release |
Building CMake from source is a custom-maintainer path for patches or nonstandard compile flags. For most Rocky Linux users who only need a newer CMake release, Kitware’s prebuilt Linux archive is faster to verify, install, update, and remove.
Both documented paths are system-wide installs and need sudo: DNF writes RPM-managed files under /usr, and the upstream helper writes under /opt and /usr/local/bin. A no-admin CMake install is better handled inside a project-specific toolchain or CI image so PATH and updates stay local to that project.
Refresh Rocky Linux Packages Before Installing CMake
Refresh package metadata and apply pending updates before installing development tools. Review the transaction before confirming, especially on shared workstations or build servers.
sudo dnf upgrade --refresh
Package-management commands use
sudobecause they modify system directories. Run them from an account with administrative privileges.
Install CMake with DNF
Install CMake from Rocky Linux AppStream:
sudo dnf install cmake
DNF installs the main cmake package plus support packages such as cmake-data and cmake-filesystem. On current Rocky releases, the transaction also pulls in make when it is not already installed, but it does not install the C++ compiler.
Install Build Tools for C++ Projects
CMake generates build files, but it does not replace a compiler. Install the C++ compiler and Make if you plan to build local C++ projects or run the test project after installation:
sudo dnf install gcc-c++ make
Rocky Linux installs the compiler and standard C++ development headers for ordinary user-space projects. If you are compiling kernel modules instead, install Linux kernel headers on Rocky Linux for the running kernel before building.
Verify CMake on Rocky Linux
Confirm the command is available:
cmake --version
Rocky Linux 10 currently returns:
cmake version 3.30.5 CMake suite maintained and supported by Kitware (kitware.com/cmake).
Rocky Linux 9 and 8 currently return the 3.26 series from AppStream:
cmake version 3.26.5 CMake suite maintained and supported by Kitware (kitware.com/cmake).
Check the exact RPM revision when a project or bug report asks which Rocky build you are using:
rpm -q cmake
Install Latest Upstream CMake on Rocky Linux
Use Kitware’s upstream binary only when the Rocky package is too old for the project you need to build. This method works on x86_64 and aarch64 Rocky Linux systems because Kitware publishes Linux archives for both architectures. Kitware also publishes .sh installers, but the .tar.gz archive keeps every installed file under one prefix.
Install Upstream Helper Requirements
Install the small tools used by the update helper to resolve the latest release, download the archive, extract it, and verify the checksum:
sudo dnf install curl python3 tar gzip
The helper uses the curl command in Linux with -fsSLO: -f fails on HTTP errors, -s hides progress noise, -S still shows errors, -L follows redirects, and -O saves the remote filename locally.
Create the Upstream CMake Update Helper
Create a reusable helper that detects the latest non-prerelease CMake tag from GitHub, maps your Rocky Linux architecture to Kitware’s archive name, verifies the SHA-256 checksum, replaces the dedicated prefix, and refreshes command symlinks. The sudo tee pattern writes the script into a root-owned path, and >/dev/null stops tee from echoing the whole script back to the terminal.
sudo tee /usr/local/bin/update-cmake-upstream >/dev/null <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
if [ "$(id -u)" -ne 0 ]; then
echo "Run this helper with sudo: sudo /usr/local/bin/update-cmake-upstream" >&2
exit 1
fi
prefix=/opt/cmake-upstream
bin_dir=/usr/local/bin
release_api=https://api.github.com/repos/Kitware/CMake/releases/latest
cmake_ver=$(curl -fsSL "$release_api" | python3 -c 'import json, sys; print(json.load(sys.stdin)["tag_name"].lstrip("v"))')
case "$(uname -m)" in
x86_64) cmake_arch=linux-x86_64 ;;
aarch64 | arm64) cmake_arch=linux-aarch64 ;;
*)
printf 'Unsupported architecture: %s\n' "$(uname -m)" >&2
exit 1
;;
esac
archive="cmake-${cmake_ver}-${cmake_arch}.tar.gz"
checksum_file="cmake-${cmake_ver}-SHA-256.txt"
base_url="https://github.com/Kitware/CMake/releases/download/v${cmake_ver}"
guard_links() {
for tool in cmake ctest cpack; do
link="${bin_dir}/${tool}"
expected="${prefix}/bin/${tool}"
if [ -L "$link" ]; then
current_target=$(readlink "$link")
if [ "$current_target" != "$expected" ]; then
printf 'Refusing to replace %s because it points to %s.\n' "$link" "$current_target" >&2
exit 1
fi
elif [ -e "$link" ]; then
printf 'Refusing to overwrite %s because it is not a symlink.\n' "$link" >&2
exit 1
fi
done
}
refresh_links() {
for tool in cmake ctest cpack; do
ln -sfn "${prefix}/bin/${tool}" "${bin_dir}/${tool}"
done
}
guard_links
current_ver=""
if [ -x "${prefix}/bin/cmake" ]; then
current_ver=$("${prefix}/bin/cmake" --version | awk '/^cmake version/ {print $3; exit}')
fi
if [ "$current_ver" = "$cmake_ver" ]; then
refresh_links
printf 'CMake %s is already installed.\n' "$cmake_ver"
exit 0
fi
work_dir=$(mktemp -d)
old_prefix=""
restore_old_prefix() {
if [ -n "$old_prefix" ] && [ -e "$old_prefix" ] && [ ! -e "$prefix" ]; then
mv "$old_prefix" "$prefix"
fi
}
cleanup() {
status=$?
restore_old_prefix
rm -rf "$work_dir"
exit "$status"
}
trap cleanup EXIT
cd "$work_dir"
curl -fsSLO "${base_url}/${archive}"
curl -fsSLO "${base_url}/${checksum_file}"
grep " ${archive}$" "$checksum_file" | sha256sum -c -
install_dir="${work_dir}/cmake-upstream"
mkdir -p "$install_dir"
tar -xzf "$archive" --strip-components=1 -C "$install_dir"
"${install_dir}/bin/cmake" --version >/dev/null
if [ -e "$prefix" ] && [ ! -d "$prefix" ]; then
printf 'Refusing to replace %s because it is not a directory.\n' "$prefix" >&2
exit 1
fi
if [ -d "$prefix" ]; then
old_prefix="${prefix}.previous.$(date +%s)"
mv "$prefix" "$old_prefix"
fi
mv "$install_dir" "$prefix"
refresh_links
if [ -n "$old_prefix" ]; then
rm -rf "$old_prefix"
old_prefix=""
fi
"${prefix}/bin/cmake" --version
EOF
Use the chmod command in Linux to make the helper executable:
sudo chmod 755 /usr/local/bin/update-cmake-upstream
Confirm the helper is available from your shell:
command -v update-cmake-upstream
/usr/local/bin/update-cmake-upstream
Install Upstream CMake with the Helper
The helper replaces the
/opt/cmake-upstreamdirectory used by this method and refreshes its/usr/local/binsymlinks. Back up anything you manually added under that directory before running it.
Run the helper to download the verified .tar.gz archive, extract it into the dedicated prefix, and activate the upstream commands. The guide to open gz and tgz files in Linux explains the tar -xzf option pattern in more detail.
sudo /usr/local/bin/update-cmake-upstream
Example output from the current x86_64 release looks like this; your version number may differ:
cmake-4.3.2-linux-x86_64.tar.gz: OK cmake version 4.3.2 CMake suite maintained and supported by Kitware (kitware.com/cmake).
Verify Upstream CMake on Rocky Linux
Check the upstream command directly from /usr/local/bin:
/usr/local/bin/cmake --version
A successful upstream install returns a CMake banner like this; your version number may differ:
cmake version 4.3.2 CMake suite maintained and supported by Kitware (kitware.com/cmake).
Test CMake with a Small C++ Project
A small build proves that CMake, the compiler, and Make are working together. Create a clean test directory and write a minimal C++ source file:
mkdir -p ~/cmake-test
cd ~/cmake-test
cat > main.cpp <<'EOF'
#include <iostream>
int main() {
std::cout << "CMake is working!" << std::endl;
return 0;
}
EOF
Create a basic CMakeLists.txt file for the project:
cat > CMakeLists.txt <<'EOF'
cmake_minimum_required(VERSION 3.10)
project(HelloCMake LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
add_executable(hello main.cpp)
EOF
Configure and build the project. The explicit Unix Makefiles generator keeps the example tied to the make package installed earlier:
cmake -S . -B build -G "Unix Makefiles"
cmake --build build
Run the compiled test binary:
./build/hello
The program should print:
CMake is working!
Remove the test project when you no longer need it:
cd ~
rm -rf ~/cmake-test
Update CMake on Rocky Linux
Update the Rocky CMake Package
The AppStream package updates with normal system maintenance. Use a targeted upgrade when you only want to check CMake and its dependencies:
sudo dnf upgrade cmake
After the upgrade, recheck the version:
cmake --version
Update Upstream CMake
For the Kitware upstream method, rerun the helper. It checks the latest release, verifies the matching archive, replaces /opt/cmake-upstream when a newer version is available, and exits cleanly when the current version is already installed.
sudo /usr/local/bin/update-cmake-upstream
If the installed upstream release is already current, the helper returns a short status line. If Kitware has published a newer release, it prints the checksum result and the new cmake --version banner instead.
Remove CMake from Rocky Linux
Remove the Rocky CMake Package
Remove the Rocky-managed package with DNF:
sudo dnf remove cmake
Verify the package is no longer installed:
rpm -q cmake || true
A removed package returns:
package cmake is not installed
If you installed gcc-c++ and make only for the test project, remove them separately after confirming no other local builds need them.
sudo dnf remove gcc-c++ make
Remove Upstream CMake
The next commands permanently delete the upstream CMake prefix and remove only symlinks that still point into that prefix. They do not remove the Rocky package under
/usr/binif you installed it separately.
for tool in cmake ctest cpack; do
link="/usr/local/bin/$tool"
target="/opt/cmake-upstream/bin/$tool"
if [ -L "$link" ] && [ "$(readlink "$link")" = "$target" ]; then
sudo rm -f "$link"
fi
done
sudo rm -rf /opt/cmake-upstream
sudo rm -f /usr/local/bin/update-cmake-upstream
hash -r
command -v update-cmake-upstream || echo "update-cmake-upstream command not found"
command -v cmake || echo "cmake command not found"
The helper removal check should print update-cmake-upstream command not found. If the Rocky package remains installed, the final CMake check should return /usr/bin/cmake. If no CMake method remains installed, it prints cmake command not found.
Troubleshoot CMake on Rocky Linux
CMake Command Not Found
If the shell cannot find CMake, either the package is missing or the current shell still has an old command path cached.
bash: cmake: command not found
Check both the RPM state and shell path:
rpm -q cmake || true
command -v cmake || echo "cmake missing from PATH"
When CMake is absent, the diagnostic returns:
package cmake is not installed cmake missing from PATH
Install the Rocky package, clear Bash’s command cache, and recheck the version:
sudo dnf install cmake
hash -r
cmake --version
CMake Cannot Find a C++ Compiler
CMake can generate build files only after it finds the compiler your project language requires. A missing C++ compiler commonly appears during project(... LANGUAGES CXX) or the first configure step.
Check whether Rocky Linux can find the C++ compiler command:
command -v c++ || echo "c++ compiler missing"
A missing compiler returns:
c++ compiler missing
If the compiler is missing, install the C++ toolchain and rerun CMake from a fresh build directory:
sudo dnf install gcc-c++ make
cmake -S . -B build-fresh -G "Unix Makefiles"
Project Requires a Newer CMake Version
Some projects declare a minimum CMake version newer than the Rocky package. A typical error looks like this:
CMake 3.28 or higher is required. You are running version 3.26.5
Rocky Linux 9 and 8 currently ship CMake 3.26.x, so projects requiring 3.28 or newer need the upstream method or a project-supported workaround. Rocky Linux 10 currently ships CMake 3.30.x, so switch methods there only when the project needs a newer 4.x release or a specific Kitware point release.
After installing the upstream method, verify the version that satisfies the project requirement:
/usr/local/bin/cmake --version
Multiple CMake Versions in PATH
If you installed both methods, check which binary your shell resolves first:
command -v cmake
cmake --version
If the upstream helper wins on PATH, the result starts like this:
/usr/local/bin/cmake cmake version 4.3.2
Rocky packages use /usr/bin/cmake, while the upstream helper creates /usr/local/bin/cmake. Remove the method you do not want, then open a new shell or run hash -r before checking again.
Use CMake Documentation After Installation
The official CMake documentation covers commands such as cmake --build, presets, toolchain files, package discovery with find_package(), CTest, and CPack. Use version-matched docs or local help when you rely on a feature that may be newer than Rocky’s packaged CMake.
Local help comes from the CMake version currently first on your PATH:
cmake --help
cmake --help-command find_package
ctest --help
Conclusion
CMake is ready for Rocky Linux builds, with the AppStream package handling routine updates and the upstream Kitware binary available when a project needs a newer release. For the next step, install Git on Rocky Linux for source control, or install Visual Studio Code on Rocky Linux if you want an editor beside the terminal.


Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags currently allowed in published comments:
<code>command</code>command<strong>bold</strong><em>italic</em><blockquote>quote</blockquote>