FedoraRHEL Based

How To Install CMake on Fedora 43

Install CMake on Fedora 43

CMake represents one of the most powerful and flexible build automation tools available to developers today. As an open-source, cross-platform build system, CMake has become the industry standard for managing complex software projects that need to support multiple compilers and operating systems. Whether you’re developing a C++ application, working with embedded systems, or managing large-scale projects, CMake streamlines the entire compilation and linking process through a unified, platform-agnostic approach.

Fedora 43 users who want to accelerate their development workflow and eliminate tedious manual build configuration will find CMake invaluable. This comprehensive guide walks you through every step of installing CMake on your Fedora 43 system. From quick installation via the package manager to advanced source compilation techniques, you’ll discover the methods that work best for your specific development needs. Understanding these installation approaches ensures you can start building robust applications efficiently and maintain your development environment with confidence.

Understanding CMake

CMake serves as a sophisticated abstraction layer between your source code and the compilation process. Rather than creating separate build configurations for Windows, macOS, and Linux, developers write a single CMakeLists.txt file that CMake translates into platform-specific build scripts. This means your project compiles seamlessly across different operating systems without modification.

The core functionality of CMake involves three distinct stages: configuration, generation, and building. During the configuration phase, CMake reads your CMakeLists.txt file and checks your system for available compilers and tools. The generation phase creates native build files appropriate for your platform—whether that’s Unix Makefiles, Visual Studio projects, or Ninja build files. Finally, your system’s native build tool compiles the actual code. This layered approach provides unprecedented flexibility and maintainability.

CMake’s widespread adoption stems from its robust feature set. It supports conditional compilation, automatic dependency detection, and integration with external libraries. Modern development frameworks like Qt, Boost, and LLVM all use CMake for building. When you install CMake on Fedora 43, you’re equipping your system with the same build infrastructure trusted by major software projects worldwide.

Prerequisites

Before proceeding with CMake installation, verify that your Fedora 43 system meets certain fundamental requirements. You’ll need sudo privileges to execute installation commands, as CMake typically gets installed in system directories that require administrative access. Additionally, ensure you have an active internet connection for downloading packages or source files.

Check whether CMake already exists on your system using the following command:

cmake --version

If this command returns version information, CMake is already installed. Run this command again after completing installation to confirm you’ve successfully upgraded to the latest version. If the command returns “command not found,” your system doesn’t have CMake installed yet, and you’re ready to proceed with this guide.

Consider your specific requirements carefully. If you primarily need a stable, well-tested version for standard development tasks, the DNF package manager approach is ideal. However, if your projects demand the absolute latest CMake features or a specific version not available in Fedora’s repositories, compiling from source becomes necessary. Your choice between these methods depends on your development priorities and system requirements.

Method 1: Installing CMake via DNF Package Manager (Recommended for Most Users)

The DNF package manager approach represents the fastest, most straightforward installation method for the vast majority of Fedora 43 users. This approach leverages Fedora’s AppStream repository, which maintains well-tested, stable versions of essential development tools. Let’s walk through each step.

Step 1: Update Your Fedora System

Updating your system before installing new software prevents potential conflicts and ensures compatibility with the latest package dependencies. This preliminary step takes just a few minutes but can save considerable troubleshooting time later.

Open your terminal and execute this command:

sudo dnf upgrade --refresh

This command refreshes your package metadata and upgrades all installed packages to their latest available versions. The refresh flag specifically clears cached repository information, ensuring you’re downloading the most current package lists. Depending on how many packages need updating, this process may take several minutes. When prompted to confirm, type “y” and press Enter to proceed.

An alternative approach uses separate commands:

sudo dnf clean all
sudo dnf update

Both approaches achieve the same result. The first clears your package cache entirely, while the second updates your system. Choose whichever syntax feels more comfortable.

Step 2: Install CMake Using DNF

With your system updated, installing CMake becomes a single, straightforward command:

sudo dnf install cmake

This command instructs DNF to locate the cmake package in Fedora’s AppStream repository and install it along with all necessary dependencies. DNF automatically resolves dependency chains, meaning if CMake requires supporting libraries, DNF installs those automatically without requiring manual intervention.

The installation process typically completes in under a minute on systems with reasonable internet connections. During installation, DNF displays detailed output showing which packages are being downloaded and installed. You’ll notice entries for “cmake” itself plus any required supporting packages. When the process completes, you’ll return to your command prompt without error messages.

Step 3: Verify the Installation

Confirming successful installation ensures CMake is properly accessible and functioning correctly. Execute this verification command:

cmake --version

This command displays the installed CMake version number and platform information. Successful output appears similar to:

cmake version 3.xx.x

CMake suite maintained and supported by Kitware (kitware.com/cmake).

The exact version number may differ depending on when you performed the installation, as Fedora’s repositories receive periodic updates. The important point is that the command successfully returns version information rather than a “command not found” error. This confirms CMake is installed and accessible throughout your system.

Additionally, verify the CMake installation location using:

which cmake

This command displays the full path to the CMake executable, typically something like /usr/bin/cmake. Confirming the installation path ensures CMake is properly integrated into your system’s PATH variable, making it accessible from any terminal location.

Method 2: Installing CMake from Source Code (For Advanced Users)

Advanced developers and those requiring the absolute latest CMake features should compile CMake directly from source code. While this method demands more time and technical understanding, it provides maximum flexibility and control over your installation. This approach becomes necessary when Fedora’s repositories don’t yet include a specific CMake version your projects require.

Step 1: Install Build Dependencies

Compiling software from source requires a complete development environment including compilers, libraries, and build tools. Installing these prerequisites prepares your system for the compilation process.

Execute this comprehensive dependency installation command:

sudo dnf install gcc gcc-c++ openssl-devel bzip2-devel libffi-devel zlib-devel wget make -y

Let’s understand what each component provides:

  • gcc and gcc-c++: These are the C and C++ compilers. CMake itself is written in C++, so these compilers are essential for the build process.
  • openssl-devel: Provides SSL/TLS cryptography libraries and development headers that CMake uses for secure operations.
  • bzip2-devel: Includes compression library headers necessary for handling compressed archives and files.
  • libffi-devel: The Foreign Function Interface development library enables calling functions from dynamically linked libraries.
  • zlib-devel: This compression library provides development headers required by various CMake components.
  • wget: A command-line download utility used to retrieve the CMake source code from the internet.
  • make: The fundamental build automation tool that compiles CMake after the bootstrap process.

The “-y” flag automatically confirms all prompts, eliminating the need for manual interaction during installation. Installation typically completes within two to three minutes depending on your system specifications and internet speed.

Step 2: Download the Latest CMake Source Code

Navigate to the official CMake GitHub releases page to identify the current stable version. The releases page displays all available versions with detailed information about new features and bug fixes.

Use wget to download the source archive:

wget https://github.com/Kitware/CMake/releases/download/v4.1.2/cmake-4.1.2-linux-x86_64.tar.gz

Replace “3.30.0” with whatever the latest stable version is at the time of your installation. You can find the current version number by visiting the GitHub releases page or checking the official CMake website. The wget command downloads the compressed archive directly to your current working directory.

Verify successful download by listing directory contents:

ls -lh cmake-*.tar.gz

This command displays the downloaded file’s size and timestamp, confirming the download completed successfully.

Step 3: Extract the Source Archive

Decompress the downloaded archive using the tar utility:

tar -zxvf cmake-4.1.2-linux-x86_64.tar.gz

Breaking down this command:

  • -z: Processes gzip compression format
  • -x: Extracts files from the archive
  • -v: Displays verbose output showing each file being extracted
  • -f: Specifies the filename to extract

This creates a new directory named “cmake-3.30.0” containing the complete source code. Navigate into this directory:

cd cmake-4.1.2

You’re now in the CMake source root directory where the compilation process begins.

Step 4: Run the Bootstrap Script

The bootstrap script prepares CMake’s build system and checks your environment for necessary tools and libraries. This script is essential for configuring the build process correctly.

Execute the bootstrap script:

./bootstrap

The bootstrap process takes several minutes as it tests your compiler, checks for required libraries, and configures build parameters. During this phase, you’ll see detailed output about detected compilers, libraries, and build system features. The process completes when you see a message indicating successful configuration. This output confirms your system has all necessary components for compilation.

Step 5: Compile CMake

After bootstrap completes successfully, compile the CMake source code:

make

The compilation process transforms CMake’s source files into executable binaries. This step typically requires five to fifteen minutes depending on your CPU speed and system load. You’ll observe continuous output showing compilation progress as files are processed. The compilation progress appears as percentages or file counts being compiled. This extended wait time allows the compiler to create optimized binaries from the source code.

Step 6: Install the Compiled Binary

Once compilation completes successfully, install CMake to system directories:

sudo make install

This command copies the compiled CMake binary and supporting files to standard system locations, typically /usr/local/bin for the executable and /usr/local/share for supporting files. The installation process completes quickly, usually within seconds.

Step 7: Verify Source Installation

Confirm the successful installation of your compiled CMake:

cmake --version

This command displays the exact version you compiled from source. The output should show the version number matching the source archive you downloaded. If this works correctly, you’ve successfully compiled and installed CMake from source.

Additionally, verify the installation location:

which cmake

For source installations, this typically returns /usr/local/bin/cmake rather than /usr/bin/cmake used by the DNF method. Both locations are equally valid and functional.

Creating a Test Project to Verify CMake Installation

After installing CMake through either method, creating and building a simple test project confirms everything works correctly. This practical test ensures your development environment is ready for real projects.

Setting Up Your Test Project

Create a new directory for your test project:

mkdir cmake-test-project
cd cmake-test-project

Creating the C++ Source File

Using your preferred text editor (nano, vim, or gedit), create a file named hello.cpp:

nano hello.cpp

Enter the following C++ code:

#include <iostream>

int main() {
    std::cout << "Hello from CMake on Fedora 43!\n";
    return 0;
}

Save the file by pressing Ctrl+X, then Y, then Enter if using nano.

Writing the CMakeLists.txt File

Create the essential CMakeLists.txt file:

nano CMakeLists.txt

Enter this CMake configuration:

cmake_minimum_required(VERSION 3.13)

project(HelloCMakeProject)

set(CMAKE_CXX_STANDARD 17)

add_executable(hello hello.cpp)

This configuration specifies:

  • cmake_minimum_required: Requires CMake version 3.13 or later
  • project: Names your project “HelloCMakeProject”
  • set(CMAKE_CXX_STANDARD 17): Uses C++17 standard
  • add_executable: Creates an executable named “hello” from the source file

Building with CMake

Create a separate build directory, a CMake best practice:

mkdir build
cd build

Run CMake to generate build files:

cmake ..

The “..” parameter tells CMake to look for CMakeLists.txt in the parent directory. This generates native build files appropriate for your system.

Build the executable:

cmake --build .

This command runs your system’s native build tool (usually make) to compile the source code.

Running Your Test Program

Execute the compiled program:

./hello

If successful, you’ll see:

Hello from CMake on Fedora 43!

This confirms CMake successfully configured the build, your compiler created the executable, and the program runs correctly. Your CMake installation is working perfectly.

Troubleshooting Common Installation Issues

Even with careful attention to instructions, occasional problems may occur. Understanding common issues and their solutions helps you resolve problems quickly.

CMake Command Not Found

If cmake --version returns “command not found” after DNF installation, your PATH variable may not include the installation directory. Verify installation:

ls /usr/bin/cmake

If this file exists, restart your terminal or reload your shell environment:

source ~/.bashrc

For source installations, verify the location:

ls /usr/local/bin/cmake

If the file doesn’t exist, re-run sudo make install in the CMake source directory.

Version Conflicts

When multiple CMake versions exist on your system, confusion may occur. Check all installation locations:

which -a cmake

This lists all CMake installations on your system. To remove an older version installed via DNF, use:

sudo dnf remove cmake

This doesn’t affect source installations in /usr/local.

Bootstrap Script Failures

If the bootstrap script fails, missing dependencies usually cause the problem. Re-run the dependency installation:

sudo dnf install gcc gcc-c++ openssl-devel bzip2-devel libffi-devel zlib-devel wget make -y

If problems persist, check for disk space:

df -h

Compilation requires adequate free space. If space is limited, consider freeing up storage.

Build Failures During Compilation

If make fails during compilation, system-specific issues are usually responsible. Check compiler versions:

gcc --version
g++ --version

Ensure you’re using reasonably recent compiler versions. Very outdated compilers may have compatibility issues with newer CMake versions.

Package Detection Issues

When CMake can’t find installed libraries during project builds, configuration problems often occur. Verify library installation paths and ensure development headers are installed. Use CMake’s verbose mode for detailed debugging:

cmake --debug-output ..

This displays detailed information about what CMake is searching for and where.

Keeping CMake Updated

Regular updates maintain security, compatibility, and access to new features. Update CMake installed via DNF:

sudo dnf upgrade cmake

This checks for newer versions in the repository and upgrades if available.

For source installations, updating requires downloading the latest source, recompiling, and reinstalling. While more involved than DNF updates, this provides access to cutting-edge CMake features and security patches.

Alternative Installation Methods

Installing via Snap

Fedora users can alternatively install CMake using Snap:

sudo snap install cmake --classic

The --classic flag grants cmake broader system access necessary for proper functioning. Snap installations provide good isolation but may have slightly different behavior compared to native installations.

Using COPR Repository

For intermediate versions between official releases, Fedora’s COPR (Cool Other Package Repo) sometimes provides newer CMake packages. Check available repositories for your Fedora version before using COPR sources.

Congratulations! You have successfully installed CMake. Thanks for using this tutorial for installing the CMake on Fedora 43 Linux system. For additional help or useful information, we recommend you check the official CMake website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button