How to Install CMake on Debian

To start, choose between the Debian repository for stability, a source build for the newest features, or the Snap package for a self-contained install. In practice, CMake is a build system generator that turns a single CMakeLists.txt into build files for Make, Ninja, and other backends, which helps keep C and C++ projects consistent across desktops, servers, and CI pipelines.

By the end, you will have CMake installed and verified, and you will also build a small project to confirm your toolchain works.

Choose Your CMake Installation Method

Overall, each method trades off version freshness, maintenance effort, and system integration. Pick the option that matches how often you need new CMake features and how much manual upkeep you want.

MethodChannelVersionUpdatesBest For
APT (Debian repository)Debian packagesDistribution defaultAutomatic via apt upgradeMost users and stable systems
Snap packageSnapcraftLatest stableAutomatic via snap refreshIsolated installs and quick upgrades
Source buildGitHub releasesLatest stableManual rebuildNew features or custom build options

In most cases, the Debian repository is recommended because it is stable, well tested, and updates automatically with regular system upgrades. However, use the Snap package when you want a newer release without compiling, and choose a source build when you need the absolute latest features or custom build options.

Install CMake on Debian

First, refresh the package index so you pull the latest metadata for your release:

sudo apt update

Method 1: Install CMake from the Debian Repository

In this method, APT installs the Debian-maintained package and keeps it updated through standard system upgrades.

sudo apt install cmake

Next, verify the installation by checking the version:

cmake --version
cmake version 3.x.x

Debian 11, 12, and 13 ship different CMake versions. The output above shows the format only, so expect your exact version to match your release.

Later, to upgrade only CMake without upgrading the whole system, run:

sudo apt install --only-upgrade cmake

Method 2: Build CMake from Source (Latest Upstream)

Source installs do not update automatically. You must rebuild CMake whenever you want a newer version.

First, install build tools and required libraries. Debian minimal images often lack these packages:

sudo apt install build-essential zlib1g-dev libssl-dev wget ca-certificates

Next, grab the latest source tarball from the CMake GitHub releases page. The example below uses version 4.2.1, and the wget command examples guide explains download flags if you want a refresher.

The version number below is an example. Check the releases page for the latest stable version and replace it in each command.

VERSION=4.2.1
wget https://github.com/Kitware/CMake/releases/download/v${VERSION}/cmake-${VERSION}.tar.gz

After that, extract the archive and enter the source directory. If you need a quick reminder, the tar command guide covers the extraction flags.

tar -xzf cmake-${VERSION}.tar.gz
cd cmake-${VERSION}

Then, configure the build system:

./bootstrap

Now, compile the source:

make

Finally, install CMake to the default /usr/local prefix:

sudo make install

After installation, verify the installed version:

cmake --version
cmake version 4.x.x

The version shown will match the release you downloaded and built.

Optional: Create an Update Script for Source Builds

For maintenance, this script fetches the latest CMake release tag from GitHub, rebuilds, and installs it. Keep it for manual runs only.

sudo mkdir -p /opt/cmake-build
sudo chown -R $USER:$USER /opt/cmake-build

Next, create the update script:

cat <<'EOF' > /opt/cmake-build/update-cmake.sh
#!/usr/bin/env bash
set -euo pipefail

for cmd in wget tar make gcc g++; do
  if ! command -v "$cmd" >/dev/null 2>&1; then
    echo "Error: $cmd is required. Install build tools first."
    exit 1
  fi
done

LATEST_TAG=$(wget -qO- https://api.github.com/repos/Kitware/CMake/releases/latest | grep -m1 -oE '"tag_name": "v[^"]+"' | cut -d '"' -f4)
if [ -z "$LATEST_TAG" ]; then
  echo "Error: Unable to determine the latest CMake version."
  exit 1
fi

LATEST_VERSION="${LATEST_TAG#v}"
CURRENT_VERSION=$(cmake --version | head -1 | awk '{print $3}')

if [ "$CURRENT_VERSION" = "$LATEST_VERSION" ]; then
  echo "CMake is already up to date ($CURRENT_VERSION)."
  exit 0
fi

WORKDIR=/opt/cmake-build
cd "$WORKDIR"

wget -q https://github.com/Kitware/CMake/releases/download/v${LATEST_VERSION}/cmake-${LATEST_VERSION}.tar.gz
tar -xzf cmake-${LATEST_VERSION}.tar.gz
cd cmake-${LATEST_VERSION}

./bootstrap
make
sudo make install

echo "Updated CMake to ${LATEST_VERSION}."
EOF
chmod +x /opt/cmake-build/update-cmake.sh
/opt/cmake-build/update-cmake.sh

Avoid running this script from cron. Source builds can fail due to missing dependencies or network errors, so run it manually and review the output.

Method 3: Install CMake via Snap

Alternatively, the Snap package delivers newer releases than the Debian repo without compilation. It installs CMake in an isolated environment while still allowing classic access when needed.

Before installing, check whether the snap command is available:

command -v snap
/usr/bin/snap

If it is missing, install snapd:

sudo apt update
sudo apt install snapd

After installation, log out and back in, or reboot, so snapd updates your session paths.

Next, install the snapd snap to stay current with snapd updates:

sudo snap install snapd

Then, install CMake with classic confinement:

sudo snap install cmake --classic

The --classic flag grants CMake full filesystem access, which is required for build tools that need to read and write project directories outside the snap sandbox.

Finally, verify the installation:

cmake --version
cmake version 4.x.x

Snap tracks the latest stable CMake release. Your output will show the current version at install time.

Later, to update the snap or review available channels, run:

sudo snap refresh cmake
snap info cmake

Testing Your CMake Installation

To confirm everything works, build a small project that validates CMake and your compiler end to end.

Install Build Tools (If Needed)

If you installed CMake via APT or Snap, first install build tools before compiling the sample program:

sudo apt install build-essential

Otherwise, if you built CMake from source, you already installed these tools.

Create a Test Project

First, create a new folder for the test project. The mkdir command guide covers additional options if you need them.

mkdir -p cmake-hello && cd cmake-hello

Next, create a minimal CMakeLists.txt:

cat <<'EOF' > CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(HelloWorld)
add_executable(hello main.cpp)
EOF
  • cmake_minimum_required sets the minimum supported CMake version for the project.
  • project names the project.
  • add_executable builds the hello binary from main.cpp.

Then, create the C++ source file:

cat <<'EOF' > main.cpp
#include <iostream>

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

Configure and Build

After that, generate the build files and compile the program:

cmake .
make

Finally, run the binary to confirm everything works:

./hello
Hello, World!

Common Issues and Solutions

Bootstrap Fails With OpenSSL Errors

If the bootstrap script reports OpenSSL errors, the OpenSSL development headers are missing.

CMake Error: Could not find OpenSSL
CMake Error: CMAKE_USE_OPENSSL is ON but a SSL library is not found!

First, check whether libssl-dev is installed:

dpkg -s libssl-dev | grep -E '^Status|^Version'
Status: install ok installed
Version: 3.x.x

If it is missing, add it and retry bootstrap:

sudo apt install libssl-dev
./bootstrap
CMake 4.x.x, Copyright 2000-2025 Kitware, Inc. and Contributors
Found GNU toolchain

Source Build Still Shows the Debian Version

If cmake --version still reports the Debian package after a source install, your shell is likely picking up /usr/bin first. Use the which command guide if you want a deeper explanation.

First, confirm which binary is active:

command -v cmake
/usr/bin/cmake

Next, temporarily prioritize the source install in your PATH:

export PATH="/usr/local/bin:$PATH"

Afterward, to make it permanent for future terminals, add it to your shell profile and reload it:

echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Finally, verify the active version:

cmake --version
cmake version 4.x.x

Permission Denied During make install

In this scenario, the install step writes to system directories, so it fails without elevated privileges.

CMake Error at cmake_install.cmake:41 (file):
  file INSTALL cannot copy file
  "/home/user/cmake-4.2.1/bin/cmake" to "/usr/local/bin/cmake".

First, confirm you are not running as root:

id -u
1000

Your UID will differ, but any non-zero value means you are not root.

Then, re-run the install with sudo, or switch to a user-writable prefix:

sudo make install

Alternatively, use a user-local install:

./bootstrap --prefix=$HOME/.local
make
make install

Finally, verify the user-local installation:

$HOME/.local/bin/cmake --version
cmake version 4.x.x

Remove CMake from Debian

When you need to uninstall CMake, use the removal steps that match your installation method. If you tried more than one method, remove the version you do not want and then confirm which binary remains on your PATH.

Uninstall the Debian Package

sudo apt remove cmake
sudo apt autoremove

Uninstall the Snap Package

sudo snap remove cmake

Clean Up the Source-Compiled Installation

The next command removes the source-compiled CMake files under /usr/local. It does not touch the Debian package in /usr/bin, but it cannot be undone.

sudo rm -f /usr/local/bin/cmake /usr/local/bin/ctest /usr/local/bin/cpack
sudo rm -rf /usr/local/share/cmake-*

Confirm the Active CMake Version

After removal, check which CMake binary your shell will run. Debian packages use /usr/bin, source installs use /usr/local/bin, and snaps use /snap/bin:

command -v cmake
/usr/bin/cmake

Then, verify the version:

cmake --version
cmake version 3.x.x

The version shown will match whichever installation remains on your system.

Conclusion

At this point, CMake is installed and verified on Debian using your preferred method, and the sample project confirms your toolchain is working. For most systems, the Debian package keeps things stable and simple, while Snap or source builds provide newer releases when you need them. Going forward, keep your chosen method updated, and you will have a reliable foundation for cross-platform C and C++ builds.

Useful CMake Links

These official resources expand on CMake features, usage, and support options:

1 thought on “How to Install CMake on Debian”

  1. 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

    Reply

Leave a Comment