CMake is an open-source build system generator that creates native makefiles and project files for virtually any compiler or IDE. Whether you need to compile C++ applications with GCC or Clang, configure Ninja for faster builds, or manage cross-platform projects with complex library dependencies, CMake simplifies the configuration process so you can focus on writing code. By the end of this guide, you will have CMake installed on Fedora, verified with a working test build, and understand how to maintain or update your installation.
Choose Your CMake Installation Method
Fedora provides CMake through its official repositories, offering a stable and well-tested version suitable for most projects. Alternatively, compiling from source gives you access to the latest features and specific version requirements. The following table summarizes your options:
| Method | Channel | Updates | Best For |
|---|---|---|---|
| DNF Package Manager | Fedora Repos | Automatic via dnf upgrade | Most users who want stability and easy maintenance |
| Source Compilation | GitHub Releases | Manual recompilation | Developers needing the latest features or specific versions |
For most users, the DNF method is recommended because it provides automatic security updates and requires minimal maintenance. Only compile from source if you specifically need features unavailable in the repository version or require custom compilation flags.
Method 1: Install CMake via Fedora AppStream
Installing CMake from the Fedora AppStream repository provides a thoroughly tested version that integrates seamlessly with your system package management. The repository version receives security updates through the standard DNF workflow and maintains compatibility with other system libraries. As a result, most C++ developers, DevOps engineers, and build system administrators find the repository version sufficient for daily work.
Update Fedora Before CMake Installation
First, update your Fedora system before installing CMake to ensure all packages are current and minimize potential conflicts during installation:
sudo dnf upgrade --refresh
Install CMake via DNF Command
Next, install CMake using DNF:
sudo dnf install cmake
Additionally, DNF automatically installs required dependencies including cmake-data, cmake-filesystem, and supporting libraries like libuv and rhash.
Verify CMake Installation
After installation completes, verify that CMake is accessible by checking its version:
cmake --version
As a result, you should see output confirming the installation:
cmake version 3.31.10 CMake suite maintained and supported by Kitware (kitware.com/cmake).
The Fedora repository version balances stability with reasonable currency. Specifically, the 3.31.x series supports modern C++20/C++23 features, handles most popular libraries, and integrates cleanly with system-wide toolchains. In contrast, CMake 4.x introduces workflow presets, enhanced diagnostics, and improved dependency handling, but remains optional unless your project specifically requires these features. Therefore, check your project documentation before deciding to compile from source.
Method 2: Install CMake via Source Compilation
Compiling CMake from source gives you access to the latest stable release or a specific version not available in Fedora repositories. However, this method requires manual updates when new versions are released, but in return provides complete control over the build configuration and installation location.
Install Build Dependencies
Before compiling CMake, install the required build tools and development libraries. These include GCC compilers for C and C++ code, OpenSSL for secure connections, compression libraries, and the Make build system:
sudo dnf install gcc gcc-c++ openssl-devel bzip2-devel libffi-devel zlib-devel wget make -y
Specifically, this command installs GCC 15.x (current on Fedora 43) along with the development headers needed to link against system libraries during the CMake build process.
Download CMake Source Code
Once dependencies are installed, download the latest stable CMake release. The following command automatically fetches the most recent version from GitHub and downloads the source archive:
CMAKE_VER=$(curl -s https://api.github.com/repos/Kitware/CMake/tags | grep -oP '"name": "v\K[0-9]+\.[0-9]+\.[0-9]+' | head -1)
echo "Downloading CMake version: $CMAKE_VER"
wget https://github.com/Kitware/CMake/archive/refs/tags/v${CMAKE_VER}.tar.gz
This command performs the following steps:
curl -squeries the GitHub API for available CMake tagsgrep -oPextracts the latest stable version number (e.g., 4.2.1)wgetdownloads the corresponding source archive
Next, extract the archive and navigate to the source directory:
tar -zxvf v*.tar.gz
cd CMake-*/
If you prefer to download a specific version manually, visit the GitHub releases page and replace the automatic download command with:
wget https://github.com/Kitware/CMake/archive/refs/tags/vX.Y.Z.tar.gz
Run the CMake Bootstrap Script
The bootstrap script prepares the build system by detecting your compiler, checking for required libraries, and generating the Makefile. If you encounter errors at this stage, verify that all dependencies from the previous step are installed correctly.
Then, run the bootstrap script:
./bootstrap
The bootstrap process may take a few minutes to complete. Upon success, you should see output indicating the configuration completed without errors:
-- The C compiler identification is GNU 15.2.1 -- The CXX compiler identification is GNU 15.2.1 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped -- Configuring done -- Generating done -- Build files have been written to: /home/user/CMake-X.Y.Z
Build and Compile CMake
Once the bootstrap script completes successfully, build CMake using the make command. The -j$(nproc) flag enables parallel compilation using all available CPU cores, which significantly reduces build time:
make -j$(nproc)
The build process typically takes 10-20 minutes on modern hardware with parallel compilation. In contrast, older systems or virtual machines may require 30 minutes or more. During compilation, the terminal displays progress for hundreds of source files. Once complete, you should see output similar to:
[100%] Building CXX object Source/CMakeFiles/CMakeLib.dir/cmVisualStudio10TargetGenerator.cxx.o [100%] Linking CXX static library libCMakeLib.a [100%] Built target CMakeLib [100%] Linking CXX executable ../bin/cmake [100%] Built target cmake
Install CMake to System Directories
After the build process completes successfully, install CMake to /usr/local using sudo:
sudo make install
Consequently, the installation copies CMake binaries and support files to system directories. You should see confirmation output like this:
-- Installing: /usr/local/bin/cmake -- Installing: /usr/local/bin/ctest -- Installing: /usr/local/bin/cpack -- Installing: /usr/local/share/cmake-4.2 -- Installing: /usr/local/doc/cmake-4.2
Verify Source-Compiled CMake Installation
After installation completes, verify the source-compiled version is active by checking the version:
cmake --version
Accordingly, you should see the version you just compiled:
cmake version X.Y.Z CMake suite maintained and supported by Kitware (kitware.com/cmake).
The version number displayed will match the version you downloaded. The source-compiled version in /usr/local/bin takes precedence over any repository-installed version because /usr/local/bin appears earlier in the default PATH.
Managing Your CMake Installation
Clean Up Build Files
After successfully installing CMake from source, remove the build directory to reclaim disk space. The compilation process creates several gigabytes of intermediate files that are no longer needed:
cd ~ && rm -rf CMake-*/ v*.tar.gz
Update CMake Installed via DNF
When using the repository version, CMake updates automatically during system upgrades. However, to manually check for and install CMake updates:
sudo dnf upgrade cmake
Update CMake Compiled from Source
In contrast, source-compiled installations require manual updates. To update to the latest version, simply run the same automatic download and build process:
CMAKE_VER=$(curl -s https://api.github.com/repos/Kitware/CMake/tags | grep -oP '"name": "v\K[0-9]+\.[0-9]+\.[0-9]+' | head -1)
echo "Updating to CMake version: $CMAKE_VER"
wget https://github.com/Kitware/CMake/archive/refs/tags/v${CMAKE_VER}.tar.gz
tar -zxvf v*.tar.gz && cd CMake-*/
./bootstrap && make -j$(nproc) && sudo make install
The new installation automatically overwrites the previous version in /usr/local/bin. Afterward, clean up the build files:
cd ~ && rm -rf CMake-*/ v*.tar.gz
Alternatively, for convenience, you can save the following script to update CMake automatically in the future. To create the script file:
cat > ~/update-cmake.sh << 'EOF'
#!/bin/bash
set -e
# Get current installed version
CURRENT=$(cmake --version 2>/dev/null | grep -oP '\d+\.\d+\.\d+' | head -1 || echo "none")
# Fetch latest version from GitHub
LATEST=$(curl -s https://api.github.com/repos/Kitware/CMake/tags | grep -oP '"name": "v\K[0-9]+\.[0-9]+\.[0-9]+' | head -1)
echo "Current version: $CURRENT"
echo "Latest version: $LATEST"
if [ "$CURRENT" = "$LATEST" ]; then
echo "CMake is already up to date."
exit 0
fi
echo "Updating CMake from $CURRENT to $LATEST..."
cd /tmp
rm -rf CMake-*/ v*.tar.gz
wget -q "https://github.com/Kitware/CMake/archive/refs/tags/v${LATEST}.tar.gz"
tar -xzf v*.tar.gz && cd CMake-*/
./bootstrap && make -j$(nproc) && sudo make install
echo "Successfully updated CMake to $LATEST"
cmake --version
EOF
chmod +x ~/update-cmake.sh
Subsequently, run the script anytime to check for and install updates:
~/update-cmake.sh
Remove CMake from Fedora
To remove the repository-installed version, use DNF:
sudo dnf remove cmake
Furthermore, DNF automatically removes unused dependencies that were installed alongside CMake.
Similarly, for source-compiled installations, remove the binaries and support files manually:
Warning: The following command permanently deletes the source-compiled CMake installation from
/usr/local. This does not affect any repository-installed version in/usr/bin.
sudo rm -rf /usr/local/bin/cmake /usr/local/bin/ctest /usr/local/bin/cpack /usr/local/bin/ccmake /usr/local/share/cmake-4.2 /usr/local/doc/cmake-4.2
After removing the source-compiled version, the repository version (if installed) automatically becomes the active version since /usr/bin/cmake remains in the PATH.
Troubleshooting Common Issues
Bootstrap Script Fails with Missing Dependencies
If the bootstrap script exits with errors about missing headers or libraries, you will see output similar to:
CMake Error: Could not find OpenSSL. Install an OpenSSL development package or configure CMake manually. -- Configuring incomplete, errors occurred!
This error typically occurs when build dependencies are missing or incomplete. Therefore, to diagnose the issue, check which development packages are currently installed:
rpm -qa | grep -E 'gcc|openssl-devel|make'
When all packages are installed correctly, you should see output listing the installed packages:
gcc-15.2.1-5.fc43.x86_64 gcc-c++-15.2.1-5.fc43.x86_64 openssl-devel-3.5.4-1.fc43.x86_64 make-4.4.1-11.fc43.x86_64
If any packages are missing from the output, install all required dependencies:
sudo dnf install gcc gcc-c++ openssl-devel bzip2-devel libffi-devel zlib-devel wget make -y
Finally, after installing the missing packages, retry the bootstrap script.
Compilation Errors During Make Process
If compilation fails with errors about undefined references or missing headers, you might see:
error: 'nullptr_t' in namespace 'std' does not name a type make[2]: *** [Source/CMakeFiles/CMakeLib.dir/build.make] Error 1
This error typically indicates an outdated compiler that lacks C++11 support. Since CMake 4.x requires GCC 7.0 or newer, check your installed GCC version:
gcc --version
On a properly configured Fedora 43 system, you should see output similar to:
gcc (GCC) 15.2.1 20251211 (Red Hat 15.2.1-5) Copyright (C) 2025 Free Software Foundation, Inc.
However, if your GCC version is older than required, update your system to install the latest compiler:
sudo dnf upgrade --refresh
Then, after updating the compiler, remove the build artifacts and restart from the bootstrap step:
rm -rf CMakeFiles CMakeCache.txt
./bootstrap
Permission Denied During Installation
The make install command requires root privileges to write to /usr/local. If you see permission errors like:
CMake Error: failed to create symlink '/usr/local/bin/cmake': Permission denied
First, verify you included sudo in the installation command. Alternatively, configure CMake to install to a user directory during bootstrap if you prefer not to use sudo:
./bootstrap --prefix=$HOME/.local
With this prefix, proceed with make and make install without sudo. The binaries install to ~/.local/bin, which is typically already in your PATH on modern Fedora systems. If CMake is not found after installation, add $HOME/.local/bin to your PATH:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
Both DNF and Source Versions Installed
If you have both the repository version and a source-compiled version installed, the source version in /usr/local/bin takes precedence because /usr/local/bin appears earlier in the default PATH. To verify which version is active:
which cmake
cmake --version
Consequently, to switch back to the repository version, remove the source-compiled binaries as described in the removal section above.
Getting Started with CMake
Now that CMake is installed, test it with a simple C++ project to verify everything works correctly. First, create a project directory and a basic source file:
mkdir ~/cmake-test && cd ~/cmake-test
cat > main.cpp << 'EOF'
#include <iostream>
int main() {
std::cout << "CMake is working!" << std::endl;
return 0;
}
EOF
Next, create a CMakeLists.txt file that tells CMake how to build your project. This file specifies the minimum CMake version, project name, C++ standard, and build targets:
cat > CMakeLists.txt << 'EOF'
cmake_minimum_required(VERSION 3.10)
project(HelloCMake)
set(CMAKE_CXX_STANDARD 17)
add_executable(hello main.cpp)
EOF
Then, build the project using the standard CMake workflow. Creating a separate build directory keeps generated files organized and makes cleanup easier:
mkdir build && cd build
cmake ..
make
You should see output confirming the build succeeded. Finally, run your compiled program:
./hello
Expected output:
CMake is working!
This workflow demonstrates the core CMake pattern: configure with cmake, build with make, and run the resulting binary. The out-of-source build approach (using a separate build directory) keeps your source tree clean and allows multiple build configurations from the same source.
Furthermore, for more complex projects, CMake supports multiple targets, external library detection via find_package(), installation rules, testing with CTest, and cross-platform builds. The official CMake documentation provides comprehensive guidance for advanced usage.
Conclusion
In conclusion, you now have CMake installed on Fedora and verified with a test build. While the DNF method provides automatic updates through system maintenance, source compilation gives you control over specific versions. From here, you can integrate CMake with Git for version control, Docker for containerized builds, or an IDE like Visual Studio Code or Code::Blocks. Additionally, for multi-language projects, consider adding Rust or Go to your toolchain.