How to Install CMake on Fedora 39/38/37 Linux

CMake, or Cross-Platform Make, is a powerful open-source build system that has revolutionized how developers compile and build software across multiple platforms. It is designed to be simple, flexible, and efficient, enabling developers to create build configurations that work seamlessly across different operating systems, compiler toolchains, and development environments. CMake achieves this by automating the process of generating native build files and workspaces for various platforms, making it an indispensable tool for modern software development.

Here are some of the key features and advantages that make CMake stand out:

  1. Cross-platform compatibility: CMake supports a wide range of platforms, including Windows, macOS, Linux, and various Unix-based systems. This ensures developers can create and maintain their projects on multiple operating systems without manually managing multiple build configurations.
  2. Flexible configuration: CMake uses a scripting language to define the build process, allowing developers to easily create custom build configurations, specify dependencies, and automate various tasks. This flexibility makes adapting CMake to different project requirements and workflows easier.
  3. Extensible architecture: CMake’s modular design allows developers to extend its functionality using custom modules and scripts. This extensibility enables the integration of third-party tools and libraries, further enhancing its utility in software development projects.
  4. Out-of-source builds: CMake allows developers to generate build files in a separate directory from the source code, keeping the source tree clean and organized. This is particularly helpful for managing large projects and makes switching between different build configurations easier.
  5. Support for multiple build systems: CMake can generate native build files for various build systems, such as GNU Make, Ninja, Visual Studio, and Xcode. This means developers can use their preferred build system and development environment while benefiting from CMake’s cross-platform capabilities.
  6. Active community and wide adoption: CMake has a large and active user base, which ensures ongoing development, improvements, and support. Many open-source projects and software organizations rely on CMake, making it a well-established and trusted choice for build automation.

This guide will demonstrate how to install CMake on Fedora Linux using two methods: with the DNF package manager and Fedora’s repository or by compiling the source code.

Section 1: Install CMake with Fedora’s Repository

In this section, we will walk you through installing CMake on your Fedora system using the repository provided by Fedora. This method is recommended for most users since it ensures you install a stable and well-tested version of CMake. If you require a specific version or the latest release, you may need to use the compile method, which will be discussed in a different section.

Step 1: Update Fedora

Ensure your system is up-to-date

Before proceeding with the installation of CMake, it is advised to update your Fedora system to ensure all existing packages are up-to-date. This helps avoid potential conflicts or issues during the installation process.

To update your Fedora system, execute the following command in your terminal:

sudo dnf upgrade --refresh

Step 2: Install CMake

Install CMake from Fedora’s AppStream repository

Installing CMake from Fedora’s AppStream repository is the recommended method for most users. This version of CMake is well-tested and stable, making it suitable for general use.

To install CMake, run the following command in your terminal:

sudo dnf install cmake

Step 3: Verify Installation of CMake

Confirm successful installation by checking the CMake version

After CMake has been installed, verifying the installation is essential by checking the installed version. This will confirm that the installation was successful and that CMake is now available on your system.

To check the CMake version, execute the following command:

cmake --version

Section 2: Install CMake by Compiling the Source

This section will guide you through installing CMake by downloading and compiling its source code. 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.

Step 1: Install the Required Packages

Install the necessary dependencies for building 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

Step 2: Download CMake Source

Obtain the latest CMake source code from GitHub

First, visit the GitHub releases page and find the link to the latest version of CMake. Keep in mind that the examples provided below might be outdated.

Next, 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

Make sure to replace {version} with the correct version number.

Step 3: Extract the Source from Archive

Unpack the downloaded CMake source code

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}

Step 4: Run the Bootstrap Script

Execute the bootstrap script to prepare for building CMake

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.

Example output once complete:

Step 5: Build CMake

Compile CMake using the make command

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.

Example when complete:

Step 6: Install CMake

Install the compiled CMake binary

After the build process is complete, install CMake using the make install command:

sudo make install

Example output:

Step 7: Verify CMake Installation

Confirm successful installation by checking the CMake version

Once the installation is complete, verify that CMake has been installed correctly by checking its version:

cmake --version

Conclusion: Installing CMake on Fedora Linux

This guide covered two different methods to install CMake on Fedora Linux. The first method utilized Fedora’s repository, which provides a stable and well-tested version of CMake. This approach is recommended for most users as it ensures easy installation and maintenance. The second method involved downloading and compiling the source code, allowing users to obtain the latest or specific version of CMake not available in the Fedora repository. This method is handy for those needing cutting-edge features or a specific version but requires manual updates by re-compiling the source code.

Following the steps outlined in this guide, you can successfully install CMake on your Fedora Linux system and leverage its powerful features in your software development projects.

Additional Resources and Links

If you’re looking for more information and resources related to CMake, here are some official sources and documentation that you can explore:

  • CMake Official Website: The official website provides comprehensive information on CMake, including its features, supported platforms, and more.
  • CMake Documentation: The official CMake documentation is invaluable for learning about various aspects of CMake, from basic usage to advanced topics.
  • CMake GitHub Repository: The official GitHub repository for CMake contains the source code, release notes, and issue tracking system. It is an excellent place to contribute, report issues, or stay updated with the latest developments.
  • CMake Wiki: The CMake Wiki contains useful information, tips, and tricks to help you make the most of CMake in your projects.

Share to...