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.
For most users, installing CMake through the DNF package manager via Fedora AppStream provides a stable and well-integrated version suitable for everyday projects. However, this guide also covers source compilation for those requiring the latest features or specific CMake versions unavailable in Fedora repositories.
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. Although Fedora typically ships stable releases rather than the absolute latest versions, this approach ensures compatibility with other system libraries and receives security updates through the standard DNF workflow. As a result, most C++ developers, DevOps engineers, and build system administrators find the repository version sufficient for daily work. Therefore, choose source compilation only when you need features exclusive to newer releases or when debugging upstream CMake issues.
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.
To refresh your system, execute this command:
sudo dnf upgrade --refresh
Install CMake via DNF Command
Next, install CMake using DNF:
sudo dnf install cmake
Verify Installation of CMake
Finally, verify the installation by checking the version:
cmake --version
You should see output similar to this, confirming the installation:
cmake version 3.30.8 CMake suite maintained and supported by Kitware (kitware.com/cmake).
The Fedora repository version balances stability with reasonable currency. The 3.30.x series supports modern C++20/C++23 features, handles most popular libraries, and integrates cleanly with system-wide toolchains. CMake 4.x introduces workflow presets, enhanced diagnostics, and improved dependency handling, but remains optional unless your project specifically requires these features. Check your project documentation before deciding to compile from source.
Method 2: Install CMake via Source
Alternatively, this method benefits users who require the latest version of CMake or a specific version not available in the Fedora repository. However, keep in mind that updating CMake with this method requires manually downloading and re-compiling the source code.
Install Initial Packages Required For CMake
Before proceeding, ensure your system has all the required dependencies for building CMake. Specifically, the build tools and development libraries include GCC compilers for C and C++ code, OpenSSL for secure connections, compression libraries, and the Make build system. To install these dependencies, use the following command:
sudo dnf install gcc gcc-c++ openssl-devel bzip2-devel libffi-devel zlib-devel wget make -y
Download the CMake Source
Once dependencies are installed, visit the GitHub releases page and find the link to the latest stable version of CMake source code.
The version numbers in this guide (4.2.0) are examples current at the time of writing. Always check the GitHub releases page for the latest stable version and substitute accordingly in all commands below.
Then, download the source code archive using wget. Remember to replace 4.2.0 in all subsequent commands with the version you selected:
wget https://github.com/Kitware/CMake/archive/refs/tags/v4.2.0.tar.gz
Extract Downloaded CMake Source Archive
After downloading, extract the contents of the archive using the following command:
tar -zxvf v4.2.0.tar.gz
Next, navigate to the extracted directory:
cd CMake-4.2.0
Run the CMake Bootstrap Script
Now you will run the bootstrap script, which prepares the build system for compiling CMake. If you encounter any issues at this stage, ensure you have installed all the required dependencies mentioned earlier.
To run the bootstrap script, execute the following command:
./bootstrap
The bootstrap script may take a few minutes to complete. Upon success, you should see output indicating successful configuration:
-- The C compiler identification is GNU 14.2.1 -- The CXX compiler identification is GNU 14.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-4.2.0
Build and Compile CMake
Once the bootstrap script has finished successfully, build CMake using the make command. For faster compilation, utilize all available CPU cores by adding the -j flag:
make -j$(nproc)
The build process typically takes 10-20 minutes on modern hardware with parallel compilation; however, older systems may require 30 minutes or more. During compilation, you will see progress for hundreds of source files. When 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 Binary
After the build process completes successfully, install CMake using the make install command:
sudo make install
As a result, the installation will copy CMake binaries 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 CMake Installation via Source
Finally, after completing the installation, check the installed CMake version to confirm everything worked correctly:
cmake --version
You should see the version you just compiled:
cmake version 4.2.0 CMake suite maintained and supported by Kitware (kitware.com/cmake).
Managing Your CMake Installation
Clean Up Build Files
After successfully installing CMake from source, you should remove the build directory to reclaim disk space. Since the compilation process creates several gigabytes of intermediate files, these are no longer needed:
cd ~ && rm -rf CMake-4.2.0 v4.2.0.tar.gz
Update CMake Installed via DNF
When using the repository version, CMake updates automatically during system upgrades. However, you can manually check for CMake updates with:
sudo dnf upgrade cmake
Update CMake Compiled from Source
In contrast, source-compiled installations require manual updates. To update, download the newer version, extract it, then repeat the bootstrap, build, and install steps. The new installation will overwrite the previous version in /usr/local/bin:
wget https://github.com/Kitware/CMake/archive/refs/tags/v4.2.1.tar.gz
tar -zxvf v4.2.1.tar.gz
cd CMake-4.2.1
./bootstrap && make -j$(nproc) && sudo make install
Uninstall CMake
To remove the repository version, use DNF:
sudo dnf remove cmake
For source-compiled installations, navigate to the original build directory and use the uninstall target. Alternatively, if you deleted the build directory, manually remove the binaries:
sudo rm -rf /usr/local/bin/cmake /usr/local/bin/ctest /usr/local/bin/cpack /usr/local/share/cmake-4.2 /usr/local/doc/cmake-4.2
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 occurs when build dependencies are missing or incomplete. To diagnose the issue, verify your installed development packages:
rpm -qa | grep -E 'gcc|openssl-devel|make'
When all packages are installed correctly, you should see output similar to:
gcc-14.2.1-6.fc41.x86_64 gcc-c++-14.2.1-6.fc41.x86_64 openssl-devel-3.2.2-8.fc41.x86_64 make-4.4.1-8.fc41.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
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. To check your GCC version, run:
gcc --version
CMake 4.x requires GCC 7.0 or newer. On a properly configured Fedora system, you should see output similar to:
gcc (GCC) 14.2.1 20240912 (Red Hat 14.2.1-3) Copyright (C) 2024 Free Software Foundation, Inc.
If your version is older than required, update your system to install the latest compiler:
sudo dnf upgrade --refresh
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 command. Alternatively, you can configure CMake to install to a user directory during bootstrap:
./bootstrap --prefix=$HOME/.local
Then proceed with make and make install without sudo. Additionally, add $HOME/.local/bin to your PATH if not already present.
Getting Started with CMake
Now that CMake is installed, you can test it with a simple C++ project. 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:
cat > CMakeLists.txt << 'EOF'
cmake_minimum_required(VERSION 3.10)
project(HelloCMake)
set(CMAKE_CXX_STANDARD 17)
add_executable(hello main.cpp)
EOF
Finally, build the project using the standard CMake workflow. Create a separate build directory to keep generated files organized:
mkdir build && cd build
cmake ..
make
You should see output confirming the build succeeded. Now 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. For more complex projects, you can explore CMake support for multiple targets, external libraries, installation rules, and cross-platform builds in the official documentation.
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 Golang to your toolchain. Related guides: CMake on Debian, Rocky Linux, Ubuntu.