Jul 12, 2024 6 min read

How to Install CMake on Debian 12

Install CMake on Debian 12 with our step-by-step tutorial. CMake simplifies software building with a powerful and flexible open-source system.

Install CMake on Debian 12
Install CMake on Debian 12
Table of Contents

Choose a different version or distribution

Introduction

Before we begin talking about how to install CMake on Debian 12, let's briefly understand – What is CMake?

CMake is a powerful and flexible open-source build system that simplifies the process of compiling and building software. With its intuitive syntax and cross-platform compatibility, CMake enables developers to efficiently manage and configure projects.

By automating the build process, CMake promotes smoother collaboration and increases productivity. Whether it's a small project or a large-scale application, CMake offers reliability and ease-of-use, making it a preferred choice among developers worldwide.

In this tutorial, you will install CMake on Debian 12. We will also address a few FAQs on how to install CMake on Debian 12.

Advantages of CMake

  1. Cross-platform: CMake supports multiple platforms, allowing developers to write build scripts that work seamlessly on different operating systems.
  2. Modular and scalable: CMake's modular structure enables easy management of complex projects, making it ideal for large-scale software development.
  3. Simple syntax: CMake's user-friendly syntax simplifies the process of defining project configurations and building scripts.
  4. Integration with various IDEs: CMake seamlessly integrates with popular integrated development environments (IDEs) like Visual Studio Code, CLion, and more.
  5. Extensibility: CMake can be extended through plugins, allowing developers to customize and adapt it to their specific project needs.

Section 1: Install CMake on Debian 12 via APT

We'll talk about using the APT package manager to install CMake on Debian in this section. The majority of users are advised to use this method because it is simple and makes use of the built-in Debian repositories.

Step 1: Update the Debian System Before Installing CMake

It is imperative that you update your Debian operating system before installing any new software to make sure all installed packages are current. This step guarantees a more seamless installation process and reduces the likelihood of conflicts. Run the subsequent command to bring your system up to date:

sudo apt update && sudo apt upgrade

Step 2: Install CMake on Debian 12 via APT Command

After updating your system, you can use the Debian repository to install CMake. Because it takes care of any necessary dependencies automatically, this method is very convenient. Use this command to start the installation:

sudo apt install cmake

Step 3: Confirm CMake Version Installed on Debian 12

It's a good idea to verify that CMake has been installed correctly by looking up its version once the installation is finished. The installed version number is also provided in this step, which can be useful in confirming compatibility with particular build systems or projects. To find out the version of CMake, run the following command:

cmake --version

Section 2: Install CMake on Debian 12 via source

We'll talk about a different way to install CMake on Debian in this section: building it from source code. Those who require the most recent version of CMake or who would prefer greater control over the installation procedure should use this method. Keep in mind that updating using this method manually involves downloading and re-compiling newer versions.

Step 1: Install Required Packages for CMake Installation on Debian

The prerequisite packages and tools need to be installed before you can compile CMake from source. Execute the subsequent command to install these prerequisites:

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

Step 2: Download the CMake Version of Choice for Debian 12

Get the most recent version by first going to the CMake GitHub releases page and downloading it. The example link below will expire, so be sure to check this page frequently.

Next, download the archive file using the wget command:

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

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

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

Use the following command to extract the contents of the archive after downloading it:

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

Note: The version you downloaded should be different from the example in this guide, so don't forget to replace {version number} with the one you currently have.

Go to the extracted directory now:

cd cmake-{version number}

Step 3: Run Bootstrap Script for CMake Installation on Debian 12

To configure the CMake build, you will run the bootstrap script in this step. Verify that you have installed all necessary dependencies if you run into any problems.

./bootstrap

The bootstrap script might finish in a few minutes.

In the event that the bootstrap script is successful, the output in your Debian terminal should look like this:

Bootstrap script for CMake on Debian
Bootstrap script for CMake on Debian

When it's finished, build the package with the make command:

make

As an alternative, you may use gmake:

gmake

When the package is built, the output in your Debian terminal ought to look something like this:

'make' build for CMake on Debian
'make' build for CMake on Debian

Step 4: Install CMake on Debian 12

Use the following make install command to install CMake after the package has been built:

sudo make install

Feel free to take a quick break; the installation process might take a few minutes.

Step 5: Confirm CMake Installation on Debian 12

Once the installation is finished, check the version of CMake to make sure it was installed correctly:

make --version
CMake version after successful compilation on Debian
CMake version after successful compilation on Debian

Section 3: Test CMake Installation with a Sample Program on Debian 12

In this section, you will learn how to create and construct a basic test program to test your CMake installation. You can use this procedure to confirm that CMake runs properly on your Debian system.

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

Initially, make a new test project directory:

mkdir cmake-test-project

Go to the directory that has just been created:

cd cmake-test-project

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

Open the newly created main.cpp C++ file in your preferred 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

Make a new file called CMakeLists.txt in the root of your project directory, then 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)

The project name, the C++ standard, the minimum required version of CMake, and the creation of the executable cmake_test_project from the main.cpp file are all specified in this CMakeLists file.

Save and close the file.

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

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

mkdir build && cd build

To use CMake to configure the project, run the following command:

cmake ..

Next, use the following command to build the test program:

make

With the help of this command, the main.cpp file will be compiled, producing the executable cmake_test_project.

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

Finally, use the following command to launch the test program:

./cmake_test_project

When everything is configured properly, the output "Hello, CMake!" should appear on the console. This validates that your Debian system's CMake installation is operating properly.

“Hello World” test using CMake on Debian
“Hello World” test using CMake on Debian

FAQs to Install CMake on Debian 12

Are there any prerequisites for installing CMake on Debian 12?

No, there are no specific prerequisites for installing CMake on Debian 12. It can be easily installed using the package manager.

Is it possible to install a specific version of CMake on Debian 12?

By default, Debian 12 installs the latest available version of CMake. However, you can manually install a specific version by following the installation instructions provided by CMake.

Does CMake have any additional dependencies on Debian 12?

No, CMake does not have any additional dependencies on Debian 12. The package manager automatically handles the required dependencies during installation.

How can I check the installed version of CMake on Debian 12?

Use the command cmake --version in your terminal, which will display the installed version of CMake

Can CMake integrate with different compilers and IDEs?

Absolutely! CMake seamlessly integrates with popular compilers and IDEs, such as GCC, Clang, Visual Studio, or Xcode.

Is CMake only used for large projects?

No, CMake can be used for both small and large projects. It offers flexibility and scalability, making it suitable for projects of various sizes.

Does CMake support building libraries and executables?

Yes, CMake supports building libraries, executables, and even complete projects by defining project structures and managing dependencies.

Conclusion

We hope this tutorial helped you understand how to install CMake on Debian 12.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.