CMake is an open-source, cross-platform tool that automates the build process of software projects. It’s widely used by developers to manage the compilation and linking of code across various platforms, providing a unified build environment. CMake’s flexibility allows it to generate native build files for different compilers and IDEs, making it an essential tool for complex projects that need to support multiple systems.
On Fedora 40 or 39, you can install CMake using the DNF package manager via Fedora’s AppStream, which provides a stable and well-integrated version. For those who require the very latest features or want more control over the installation, an alternative method is to download, compile, and install the latest CMake version from the source. This guide will walk you through both installation methods, allowing you to choose the best approach based on your needs.
Method 1: Install CMake via Fedora’s Appstream
The first method suits most users and developers, as Fedora is an upstream-focused distribution. The second section is for those requiring the latest version of CMake.
Update Fedora Before CMake Installation
Update your Fedora system before installing CMake to ensure all packages are current and minimize potential conflicts or issues during installation.
Run the following command in your terminal to update Fedora:
sudo dnf upgrade --refresh
Install CMake via DNF Command
For most users, installing CMake from Fedora’s AppStream repository is recommended. This well-tested and stable version is ideal for general use.
Run the following command in your terminal to install CMake:
sudo dnf install cmake
Verify Installation of CMake
Once you have installed CMake, verify the installation by checking the version. This confirmation ensures a successful installation and the availability of CMake on your system.
To check the CMake version, run the following command:
cmake --version
Method 2: Install CMake via source
This method benefits users who require the latest version of CMake or a specific version not available in the Fedora repository. However, it is essential to remember 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. You can install these dependencies using the following command:
sudo dnf install gcc gcc-c++ openssl-devel bzip2-devel libffi-devel zlib-devel wget make -y
Download the CMake Source
First, visit the GitHub releases page and find the link to the latest version of CMake.
After grabbing a fresh link, download the source code archive using the wget command:
wget https://github.com/Kitware/CMake/releases/download/v{version}/cmake-{version}-linux-x86_64.tar.gz
Note: Replace {version} with the correct version number.
Extract Downloaded CMake Source Archive
Extract the contents of the downloaded archive using the following command:
tar -zxvf cmake-{version number}.tar.gz
Now, navigate to the extracted directory:
cd /cmake-{your version}
Run the CMake Bootstrap Script
In this step, you will run the bootstrap script, which prepares the build system for compiling CMake. If you encounter any issues, ensure you have installed all the required dependencies mentioned earlier.
Run the bootstrap script with the following command:
./bootstrap
The bootstrap script may take a few minutes to complete.
Build and Compile CMake
Once the bootstrap script has finished, use the make
command to build CMake:
make
The build process can take several minutes, so you might want to grab a coffee or take a short break while waiting.
Install CMake Binary
After the build process is complete, install CMake using the make install command:
sudo make install
Verify CMake Installation via Source
After completing the installation, check the installed CMake version to ensure the correct installation:
cmake --version
Conclusion
By installing CMake on Fedora through the DNF package manager and Fedora’s AppStream, you’ve ensured that your system has a stable and reliable version of this essential build tool. Alternatively, if you opted to compile CMake from the source, you now have access to the latest features and greater control over your build environment. Whichever method you chose, keeping CMake updated will help maintain your development environment’s efficiency and compatibility. With CMake set up on your Fedora system, you’re well-prepared to manage and automate complex build processes across multiple platforms.