To install CMake on Debian, developers have four proven paths: the default APT repository for stable releases, Kitware’s official repository for newer versions with automatic updates, source compilation for cutting-edge features and customization, or Snap packages for isolated installations. CMake functions as a build system generator rather than a build system itself, producing project files for Make, Ninja, Visual Studio, and other backends from a single portable configuration. This approach unifies cross-platform C and C++ builds across desktop, mobile, and embedded targets, eliminating the need for separate build scripts per toolchain.
This guide covers all installation methods with complete verification steps, helping you choose the approach that matches your development workflow and version requirements.
Choose Your CMake Installation Method
Debian offers multiple paths to install CMake, each suited to different development needs. Choose based on your version requirements, maintenance preferences, and system constraints. The default APT repository (Debian’s package manager, similar to Windows Update) delivers stable, well-tested releases that integrate seamlessly with Debian’s update mechanism, making it the recommended starting point for most users. However, if you need cutting-edge features or want to avoid system package dependencies, alternative methods provide viable options.
The default APT repository provides tested stable releases that integrate cleanly with system updates. Kitware maintains an official APT repository with newer releases for users who need recent features without compilation overhead. Source compilation delivers the latest upstream features at the cost of manual maintenance. Snap packages offer containerized installations when system-wide integration is not required.
| Method | Version/Channel | Maintenance | Best For |
|---|---|---|---|
| APT Repository (Default) | Stable (3.18-3.25 typically) | Automatic via apt upgrade | Production environments, CI/CD pipelines, most development work |
| Kitware APT Repository | Recent stable (3.29+) | Automatic via apt upgrade | Newer versions without compilation overhead |
| Source Compilation | Latest upstream (3.30+) | Manual rebuild for updates | Cutting-edge features, custom build options, testing new releases |
| Snap Package | Latest stable | Automatic snap refresh | Isolated environments, non-root installations |
Most users should start with the default APT repository since it balances stability, maintenance convenience, and compatibility with Debian’s ecosystem. The version lag rarely affects typical build workflows, and system updates handle security patches automatically. When you need newer features without compilation overhead, Kitware’s official repository provides recent stable releases with automatic updates through the standard system update mechanism. Source compilation makes sense only when you specifically need cutting-edge features or custom build flags, but expect to rebuild manually whenever security updates or new releases appear.
Installing CMake on Debian
Before proceeding with any installation method, update your package lists to ensure access to the latest versions:
sudo apt update
Optionally, apply pending system updates if you want to upgrade all packages (not required for CMake installation):
sudo apt upgrade
Method 1: Install CMake via Debian Default Repository
Verify Current CMake Installation
Minimal Debian images sometimes ship with CMake already installed. Verify the current status before installing anything new:
cmake --version
If a version number appears, you can skip to the testing section. Otherwise, continue with the package installation below.
Install CMake via APT
Install CMake from Debian’s default repository:
sudo apt install cmake
Verify Installation
After installation completes, confirm that CMake is ready by checking its version:
cmake --version
This method works reliably for most development tasks and installs the version available in Debian’s repository.
Method 2: Install CMake via Kitware APT Repository
Kitware maintains an official APT repository that provides newer CMake releases than Debian’s default repositories without requiring source compilation. This method combines automatic updates with access to recent stable versions, making it ideal when you need newer features but want to avoid manual maintenance.
Remove Existing CMake Installation
First, if you previously installed CMake via Debian’s default repository, remove it to avoid version conflicts:
sudo apt remove --purge cmake
Install Required Dependencies
Next, install the necessary tools to add the Kitware repository. The lsb-release package ensures the lsb_release command is available on minimal images:
sudo apt update
sudo apt install ca-certificates gpg wget lsb-release
Add Kitware GPG Key
Then, download and install Kitware’s signing key to verify package authenticity:
wget -qO- https://apt.kitware.com/keys/kitware-archive-latest.asc | gpg --dearmor | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null
Add Kitware Repository
Add the Kitware repository for your Debian version. Debian 12 (Bookworm) and Debian 13 (Trixie) use the modern DEB822 .sources format by default, while Debian 11 (Bullseye) uses the legacy .list format.
Kitware limits this repository to Debian 12 (Bookworm) and Debian 13 (Trixie) on x86_64 or ARM hardware. Older versions and architectures fall outside official support, so stick with Debian’s default packages or compile CMake from source if you run anything else.
For Debian 12 (Bookworm) and Debian 13 (Trixie), create a DEB822 .sources file:
cat <<EOF | sudo tee /etc/apt/sources.list.d/kitware.sources
Types: deb
URIs: https://apt.kitware.com/debian/
Suites: $(lsb_release -cs)
Components: main
Signed-By: /usr/share/keyrings/kitware-archive-keyring.gpg
Architectures: $(dpkg --print-architecture)
EOF
For Debian 11 (Bullseye) or if you prefer the legacy format, use a .list file instead:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/debian/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/kitware.list
Update Package Lists and Install CMake
Finally, refresh the package cache and install CMake from Kitware’s repository:
sudo apt update
sudo apt install cmake
Verify Installation
Confirm the installation by checking the CMake version:
cmake --version
The output should display a version number from Kitware’s repository, typically newer than Debian’s default package. Future updates will automatically install through your regular system update workflow.
Method 3: Install CMake by Compiling Source
Source compilation requires manual rebuilding whenever security patches or new releases appear. Debian’s APT repository and Kitware’s official APT repository both handle updates automatically through your regular system update workflow, eliminating manual maintenance overhead.
For advanced users or those requiring the latest features, compiling from source delivers cutting-edge functionality and build customization options. This method involves downloading, building, and installing the source code manually.
Required Build Tools and Libraries
Before starting, install the necessary tools and libraries for the build process. The build-essential package includes the GCC compiler and other essential build tools. Run the following command:
sudo apt install build-essential zlib1g-dev libssl-dev -y
Download Latest Source Archive
Next, visit the CMake GitHub Releases page and locate the latest .tar.gz source archive. Use wget to download it, replacing X.X.X with the desired version number:
wget https://github.com/Kitware/CMake/releases/download/vX.X.X/cmake-X.X.X.tar.gz
Extract Source Archive
Once downloaded, extract the archive using the tar command:
tar -zxvf cmake-X.X.X.tar.gz
After extraction completes, navigate to the extracted directory:
cd cmake-X.X.X
Build and Install
First, run the bootstrap script to configure the environment and check dependencies:
./bootstrap
Expected output highlights successful dependency checks and ends with “Generating done”:
--------------------------------------------- * Qt support disabled * Tests are not compiled * CPack generators: TGZ --------------------------------------------- Generating done Configuring done
Once complete, compile the source code using:
make
The build finishes with 100% progress and a message similar to:
[100%] Built target cpack [100%] Built target ctest [100%] Built target cmake
Finally, install the compiled CMake package:
sudo make install
This final step might take a few minutes to complete.
Verify Installation
After installation finishes, confirm the installation by checking the CMake version:
cmake --version
Method 4: Install CMake via Snap
Snap packages provide containerized installations that run independently of system libraries, making them useful for isolated development environments or systems where you cannot modify global packages. Additionally, the CMake snap automatically updates to the latest stable release through Snap’s background refresh mechanism.
Install Snapd
Debian does not include snapd by default. Verify whether it is already installed:
snap version
If the command fails, install snapd with the following commands:
sudo apt update
sudo apt install snapd
Create the required /snap mount point for classic snaps (ignore the warning if the link already exists), then log out and back in to refresh your environment:
sudo ln -s /var/lib/snapd/snap /snap
Install CMake Snap Package
Classic confinement grants the CMake snap full system access similar to traditionally installed packages. This differs from strict confinement that sandboxes applications. Classic mode is necessary for CMake to access project files and build directories across your filesystem without permission restrictions.
Install CMake using the classic confinement mode, which grants access to system files and directories necessary for build operations:
sudo snap install cmake --classic
The --classic flag allows CMake to interact with your development environment without sandbox restrictions that would prevent accessing project files outside your home directory.
Verify Installation
Confirm the snap installation by checking the version:
cmake --version
Snap automatically manages updates, typically refreshing to new stable releases within days of upstream publication. Use the following commands whenever you need to trigger manual updates or inspect the available channels:
sudo snap refresh cmake
snap info cmake
Testing Your CMake Installation
After installation completes, verify CMake works correctly by creating and building a simple “Hello, World!” program. This confirms the installation is functional and ready for development work.
Install Build Tools (if needed)
If you installed CMake via the default APT repository, Kitware repository, or Snap instead of compiling from source, you need to install build tools to compile the test program:
sudo apt install build-essential
If you compiled CMake from source, you already have these tools and can skip this step.
Create Test Directory
Create a dedicated directory for the test project to keep files organized:
mkdir test-hello && cd test-hello
Set Up CMakeLists.txt
The CMakeLists.txt file is the heart of a CMake project, specifying the build configuration. First, use the nano editor to create this file in the test directory:
nano CMakeLists.txt
Next, add the following configuration to define the project and its executable:
cmake_minimum_required(VERSION 3.16)
project(HelloWorld)
add_executable(hello main.cpp)
cmake_minimum_required: Ensures the CMake version meets the minimum required for the project.project: Names the project, in this case,HelloWorld.add_executable: Specifies the executable target and its source file.
Save and exit the editor by pressing CTRL+X, then Y, and finally Enter.
Create C++ Source File
Next, write a basic C++ program to print “Hello, World!” to the terminal. Create main.cpp in the same directory:
nano main.cpp
Then, enter the following code into the file:
#include <iostream>
int main()
{
std::cout << "Hello, World!" << std::endl;
return 0;
}
This code uses the C++ standard library to output “Hello, World!” to the terminal. Save and close the file using the same process as before (CTRL+X, Y, Enter).
Generate Build System
Now, generate the build system using CMake:
cmake .
CMake processes CMakeLists.txt and generates a Makefile in the current directory.
Build the Program
Next, compile the program using make, which reads the generated Makefile and builds the hello executable:
make
The terminal output will display the compilation process, confirming the creation of the hello executable.
Run the Program
Finally, run the compiled program to verify everything works correctly:
./hello
You should see the following output in the terminal:
Hello, World!
This confirms that CMake is installed and functioning as expected on your system.
Common Issues and Solutions
While CMake installation typically proceeds smoothly, certain scenarios can cause errors. The solutions below address the most common issues encountered on Debian systems.
Missing Build Dependencies During Source Compilation
If the bootstrap script fails with “Could not find OpenSSL” or similar library errors, you’ll need to install the missing development packages. The build-essential package group covers most requirements, but additional libraries may be needed.
First, check for the specific error message:
./bootstrap
You may see output similar to:
CMake Error: Could not find OpenSSL CMake Error: CMAKE_USE_OPENSSL is ON but a SSL library is not found!
Install the missing development libraries:
sudo apt install libssl-dev libcurl4-openssl-dev
After installing dependencies, run bootstrap again to verify the issue is resolved.
Version Conflicts with Existing Installations
When multiple CMake versions exist (APT package plus manual source build), check which binary your shell finds:
which cmake
The output shows the active path:
/usr/bin/cmake
Check all installed versions:
/usr/bin/cmake --version
/usr/local/bin/cmake --version
If both versions exist, you have two options. First, remove the APT package to avoid conflicts:
sudo apt remove cmake
Alternatively, ensure /usr/local/bin precedes /usr/bin in your PATH environment variable to prioritize the source-compiled version. Check your current PATH:
echo $PATH
Verify the source-compiled version is now active:
cmake --version
Slow Source Compilation on Limited Hardware
Compiling CMake on systems with fewer than 2 CPU cores or limited RAM can take 30-60 minutes. To accelerate the build, limit parallel jobs to match available cores.
Check your CPU core count:
nproc
Example output showing 2 cores:
2
Replace the standard make command with a parallelized version matching your core count:
make -j2
For systems with 4 cores, use the following command to maintain reasonable build speed without exhausting memory:
make -j4
The compilation will show multiple files building simultaneously:
[ 10%] Building CXX object Source/CMakeFiles/CMakeLib.dir/cmakefile.cxx.o [ 11%] Building CXX object Source/CMakeFiles/CMakeLib.dir/cmSourceFile.cxx.o [ 12%] Building CXX object Source/CMakeFiles/CMakeLib.dir/cmTarget.cxx.o ...
Permission Denied During make install
The installation step writes to system directories requiring root access. If make install fails with permission errors, you’ll see output similar to:
CMake Error at cmake_install.cmake:41 (file): file INSTALL cannot copy file "/home/user/cmake-3.30.0/bin/cmake" to "/usr/local/bin/cmake". Call Stack (most recent call first): cmake_install.cmake:99 (include)
The simplest solution is to prefix the command with sudo:
sudo make install
Alternatively, configure a user-writable installation prefix during bootstrap to avoid needing elevated privileges. This installs CMake to your home directory:
./bootstrap --prefix=$HOME/.local
Then complete the build and install without sudo:
make
make install
Verify CMake is accessible from your PATH:
~/.local/bin/cmake --version
Add $HOME/.local/bin to your PATH if needed by adding this line to ~/.bashrc:
export PATH="$HOME/.local/bin:$PATH"
Conclusion
CMake delivers efficient cross-platform build automation for C and C++ projects through its declarative configuration system. Debian offers multiple installation paths to match different workflow requirements: the default APT repository balances stability and maintenance simplicity, Kitware’s official repository provides newer releases with automatic updates, source compilation grants access to cutting-edge features with full customization, and Snap packages offer containerized isolation. Your Debian system now runs a working CMake installation verified through a functional Hello World example, ready for production builds or development environments.
Useful CMake Links
Here are some helpful resources to further enhance your understanding and usage of CMake. These links are directly related to the content covered in this guide and provide additional support for both beginners and advanced users:
- CMake Getting Started Guide
Explore the official CMake getting started guide to familiarize yourself with the basics of using CMake for your projects. - CMake Documentation
Access the comprehensive documentation for CMake, covering everything from basic commands to advanced usage and customization. - CMake Support Page
If you need help or have questions about CMake, visit the official support page for FAQs, forums, and additional resources. - CMake GitHub Repository
Stay updated with the latest CMake releases, source code, and contributions by exploring its GitHub repository.
All steps succeed without any problem. A very clear easy-to-understand tuto. Thanks a lot. Pierre
HP Pavilion dv7-4302EZ (2011) ; Debian version 11.11 ; Xfce 4.16