How to Install CMake on Debian 12, 11 or 10

Diving into software development on Debian platforms requires a reliable build system, and CMake stands out as a top choice. This guide focuses on how to install CMake on Debian 12 Bookworm, Debian 11 Bullseye, or Debian 10 Buster. With CMake, developers gain a versatile tool that streamlines the creation of software applications across diverse platforms, from Linux and macOS to Windows.

Key Attributes of CMake for Debian Users:

  • Cross-Platform Support: CMake’s adaptability ensures your projects remain buildable across many operating systems.
  • Language Versatility: Whether your project is in C, C++, or Fortran, CMake has you covered.
  • Modularity: Craft reusable modules and scripts with CMake, enhancing project consistency.
  • Build System Flexibility: CMake can generate the necessary build files from Make and Ninja to Xcode and Visual Studio.
  • Scalability: Tackle large projects with intricate dependencies effortlessly, thanks to CMake’s design.
  • Customization: Tailor your build logic with CMake’s scripting capabilities to meet specific project requirements.

With these features in mind, the subsequent sections of this guide will delve into the installation processes for CMake on Debian, covering both the APT method and source compilation.

Section 1: Install CMake on Debian 12, 11, or 10 via APT

This section will discuss installing CMake on Debian using the APT package manager. This method is recommended for most users, as it is straightforward and utilizes the default Debian repositories.

Step 1: Update the Debian System Before Installing CMake

Before installing any new software, it is essential to update your Debian operating system to ensure all existing packages are up to date. This step helps minimize potential conflicts and ensures a smoother installation process. Execute the following command to update your system:

sudo apt update && sudo apt upgrade

Step 2: Install CMake on Debian 12, 11, or 10 via APT Command

Now that your system is up-to-date, you can install CMake from Debian’s repository. This method is convenient because it automatically takes care of any required dependencies. To begin the installation, use the following command:

sudo apt install cmake

Step 3: Confirm CMake Version Installed on Debian 12, 11 or 10

Once the installation is complete, it’s a good practice to confirm that CMake has been installed correctly by checking its version. This step also provides the installed version number, which can help verify compatibility with specific projects or build systems. Run the following command to check the version of CMake:

cmake --version

Section 2: Install CMake on Debian 12, 11, or 10 via source

This section will discuss an alternative method for installing CMake on Debian – compiling it from the source code. This approach is suitable for users who need the latest version of CMake or want more control over the installation process. Remember that this method requires manual updates by downloading and re-compiling newer versions.

Step 1: Install Required Packages for CMake Installation on Debian

Before compiling CMake from the source, you must install the necessary packages and tools. Run the following command to install these dependencies:

sudo apt install build-essential checkinstall zlib1g-dev libssl-dev -y

Step 2: Download the CMake Version of Choice for Debian 12, 11 or 10

First, visit the CMake GitHub releases page and grab the download link for the latest version. Remember to check this page regularly, as the example link below will become outdated.

Next, use the wget command to download the archive file:

wget https://github.com/Kitware/CMake/releases/download/{version}/cmake-{version}.tar.gz

For example, if you want to download version 3.27.1, use the following command:

wget https://github.com/Kitware/CMake/releases/download/v3.27.1/cmake-3.27.1.tar.gz

After downloading the archive, extract its contents using the following command:

tar -zxvf cmake-{version number}.tar.gz

Note: Remember to replace {version number} with the current version you downloaded, as it should differ from the example in this guide.

Now, change to the extracted directory:

cd cmake-{version number}

Step 3: Run Bootstrap Script for CMake Installation on Debian 12, 11 or 10

In this step, you will run the bootstrap script to configure the CMake build. If you encounter any issues, double-check that all required dependencies have been installed.

./bootstrap

The bootstrap script may take a few minutes to complete.

If the bootstrap script is successful, you should see a similar output in your Debian terminal:

Screenshot of a successful bootstrap script for CMake on Debian 12, 11 or 10 Linux terminal.
Terminal screenshot showcasing the successful bootstrap script for CMake on Debian.

Once it’s done, use the make command to build the package:

make

Alternatively, you can run gmake:

gmake

Once the package has been built, you should see a similar output in your Debian terminal:

Screenshot of a completed make build for CMake on Debian 12, 11 or 10 Linux terminal.
Terminal screenshot displaying the successful completion of a make build for CMake on Debian.

Step 4: Install CMake on Debian 12, 11 or 10

Now that the package has been built install CMake using the following make install command:

sudo make install

The installation process may take several minutes, so feel free to take a short break.

Step 5: Confirm CMake Installation on Debian 12, 11 or 10

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

make --version
Screenshot showing the version output of CMake after compilation on Debian 12, 11 or 10 Linux terminal.
Terminal screenshot revealing the CMake version after successful compilation on Debian.

Section 3: Test CMake Installation with a Sample Program on Debian 12, 11 or 10

This section will demonstrate how to test your CMake installation by creating and building a simple test program. This process will help you verify that CMake functions correctly on your Debian system.

Step 1: Create a Project Directory for the CMake Test on Debian

First, create a new directory for your test project:

mkdir cmake-test-project

Navigate to the newly created directory:

cd cmake-test-project

Step 2: Write a Simple C++ Program for the CMake Test on Debian

Create a new C++ file called main.cpp and open it in your favorite text editor:

nano main.cpp

Add the following code to main.cpp:

#include <iostream>

int main() {
    std::cout << "Hello, CMake!" << std::endl;
    return 0;
}

Save and close the file.

Step 3: Create a CMakeLists.txt File for the CMake Test on Debian

In the root of your project directory, create a new file named CMakeLists.txt and open it in a text editor:

nano CMakeLists.txt

Add the following content to CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)
project(cmake_test_project)

set(CMAKE_CXX_STANDARD 14)

add_executable(cmake_test_project main.cpp)

This CMakeLists file defines the minimum required CMake version, sets the project name, specifies the C++ standard, and creates an executable named cmake_test_project from the main.cpp file.

Save and close the file.

Step 4: Configure and Build the Test Program with CMake on Debian

Now, create a new directory called build inside your project directory:

mkdir build && cd build

Run the following command to configure the project using CMake:

cmake ..

Next, build the test program using the following command:

make

This command will compile the main.cpp file and generate an executable called cmake_test_project.

Step 5: Run the Test Program to Verify CMake Installation on Debian

Finally, run the test program using the following command:

./cmake_test_project

If everything has been set up correctly, you should see the output “Hello, CMake!” printed on the console. This confirms that your CMake installation is working correctly on your Debian system.

Screenshot of a successful "Hello World" test with CMake on Debian 12, 11 or 10 Linux terminal.
Terminal screenshot demonstrating a successful “Hello World” test using CMake on Debian.

Conclusion

This guide has explored two different methods for installing CMake on Debian Linux systems. The first method, the APT package manager, is recommended for most users due to its simplicity and ease of use. This approach utilizes the default Debian repositories and automatically manages all required dependencies.

The second method, compiling CMake from source, is suitable for users needing the latest version of CMake or wanting more control over the installation process. While this approach provides greater flexibility, it requires manual updates and a more in-depth understanding of the build process.

Both methods have their advantages and are suitable for different use cases. Ultimately, choosing these two methods depends on your requirements, preferences, and familiarity with the Debian Linux system. Regardless of your chosen method, CMake is a powerful and versatile build system that can significantly streamline your software development process on various platforms and environments.

Your Mastodon Instance
Share to...