How to Install CMake on Ubuntu (26.04, 24.04, 22.04)

Install CMake on Ubuntu when you need a cross-platform build system generator for C and C++ projects. CMake turns a single CMakeLists.txt into build files for Make, Ninja, and IDEs, so you can keep one configuration across local development, CI, and different operating systems.

This guide covers four practical ways to install CMake on Ubuntu: the default APT package, Kitware’s official APT repository for newer releases, the Snap package, and building from source when you need the latest upstream features.

Choose Your CMake Installation Method

Ubuntu’s default APT package is the simplest and most stable option, but it can lag behind upstream releases. Kitware’s repository provides newer versions on supported LTS releases, Snap offers an isolated package with classic confinement, and source builds let you control the exact version and build flags.

MethodVersion AvailabilityMaintenanceBest For
APT Repository (Default)Ubuntu’s packaged version (varies by release)Automatic via system updatesMost development work, CI pipelines, stable builds
Kitware APT RepositoryNewer upstream releases (24.04 and 22.04 only)Automatic via system updatesNewer features without manual compilation
Snap PackageLatest stable upstream (all releases)Automatic snap refreshIsolated installs or Snap-first workflows
Source CompilationAny version you compileManual rebuild for updatesCutting-edge features or custom build options

These steps cover Ubuntu 26.04 LTS, 24.04 LTS, and 22.04 LTS. Kitware’s repository ships packages for 24.04 and 22.04 only, while the default APT package, Snap, and source builds work across all supported LTS releases. The commands are the same on each supported LTS unless a note says otherwise.

If you are not sure where to start, use the default APT package. Choose Kitware’s repository when you need a newer version without compiling, Snap if you prefer isolated packaging, and source builds when you want the newest upstream release or custom build options.

Installing CMake on Ubuntu

Pick one method below. Each method ends with a version check so you can confirm CMake is on your PATH.

Method 1: Install CMake from Ubuntu’s Default APT Repository

This option is the simplest and integrates with normal system updates. Ubuntu ships CMake packages for all supported releases through the default repositories.

Update your package index and install CMake:

sudo apt update
sudo apt install cmake
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Hit:1 http://security.ubuntu.com/ubuntu resolute-security InRelease
Hit:2 http://archive.ubuntu.com/ubuntu resolute InRelease
Hit:3 http://archive.ubuntu.com/ubuntu resolute-updates InRelease
Hit:4 http://archive.ubuntu.com/ubuntu resolute-backports InRelease
Reading package lists...
Building dependency tree...
Reading state information...
30 packages can be upgraded. Run 'apt list --upgradable' to see them.

Verify the installed version:

cmake --version
Ubuntu 26.04:
cmake version 3.31.6

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

Ubuntu 24.04:
cmake version 3.28.3

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

Ubuntu 22.04:
cmake version 3.22.1

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

To update later using APT, run sudo apt install --only-upgrade cmake.

Method 2: Install CMake from Kitware’s APT Repository

Kitware maintains an official APT repository that ships newer CMake releases than Ubuntu’s default package without requiring a source build.

Kitware publishes packages for Ubuntu 24.04 and 22.04 only. If you run Ubuntu 26.04, use the default APT package, Snap, or the source build method.

Install the repository tools:

sudo apt install ca-certificates curl gpg lsb-release

Download and store the signing key in the system keyring:

curl -fsSL https://apt.kitware.com/keys/kitware-archive-latest.asc | sudo gpg --dearmor -o /usr/share/keyrings/kitware-archive-keyring.gpg

Add the Kitware repository using DEB822 format:

cat <<EOF | sudo tee /etc/apt/sources.list.d/kitware.sources
Types: deb
URIs: https://apt.kitware.com/ubuntu
Suites: $(lsb_release -cs)
Components: main
Architectures: $(dpkg --print-architecture)
Signed-By: /usr/share/keyrings/kitware-archive-keyring.gpg
EOF

Refresh your package index:

sudo apt update
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Hit:1 http://security.ubuntu.com/ubuntu noble-security InRelease
Hit:2 http://archive.ubuntu.com/ubuntu noble InRelease
Get:3 https://apt.kitware.com/ubuntu noble InRelease [15.5 kB]
Hit:4 http://archive.ubuntu.com/ubuntu noble-updates InRelease
Hit:5 http://archive.ubuntu.com/ubuntu noble-backports InRelease
Get:6 https://apt.kitware.com/ubuntu noble/main amd64 Packages [50.6 kB]
Fetched 66.2 kB in 2s (41.9 kB/s)
Reading package lists...
Building dependency tree...
Reading state information...
10 packages can be upgraded. Run 'apt list --upgradable' to see them.

Install Kitware’s keyring package so future key updates are handled automatically:

sudo apt install kitware-archive-keyring

Confirm that APT will pull CMake from Kitware before installing:

apt-cache policy cmake | sed -n '1,10p'
cmake:
  Installed: (none)
  Candidate: 4.2.1-0kitware1ubuntu24.04.1
  Version table:
     4.2.1-0kitware1ubuntu24.04.1 500
        500 https://apt.kitware.com/ubuntu noble/main amd64 Packages

Install CMake from Kitware:

sudo apt install cmake

Verify the installed version:

cmake --version
cmake version 4.2.1

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

To update later using APT, run sudo apt install --only-upgrade cmake.

Method 3: Install CMake via Snap

Snap packages are self-contained and update automatically through Snap’s refresh mechanism. The CMake snap is maintained by Kitware and published on the Snap Store.

Check whether snapd is available:

snap version
snap          2.73+ubuntu24.04
snapd         2.73+ubuntu24.04
series        16
ubuntu        24.04
kernel        6.6.87.2-microsoft-standard-WSL2
architecture  amd64

If the command is missing, install snapd with sudo apt install snapd. Your kernel line will differ from the example above.

Classic confinement gives the CMake snap full system access so it can read and write build directories without permission prompts. This is required for most development workflows.

Install the CMake snap with classic confinement:

sudo snap install cmake --classic

Verify the installed version:

cmake --version
cmake version 4.2.1

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

To refresh updates or view available channels, use:

sudo snap refresh cmake
snap info cmake
channels:
  latest/stable:    4.2.1   2025-12-08 (1507)  56MB classic
  latest/candidate: ^                               
  latest/beta:      ^                               
  latest/edge:      ^                               
  4.2/stable:       4.2.1   2025-12-08 (1507)  56MB classic
  4.2/candidate:    ^                               

Method 4: Compile CMake from Source

Source builds give you the latest upstream release and full control over build options, but you must rebuild manually when a new version ships. Review the official CMake installation documentation for detailed build requirements.

Install Build Dependencies

Install the build tools and OpenSSL headers required by the bootstrap step. The Install GCC on Ubuntu guide covers the compiler toolchain if you need more detail.

sudo apt install build-essential curl libssl-dev

Download the Latest Source Archive

Use curl to detect the latest GitHub tag and download the matching source archive:

CMAKE_TAG=$(curl -s https://api.github.com/repos/Kitware/CMake/tags | grep -m1 '"name": "v' | sed -E 's/.*"name": "([^"]+)".*/\1/')
CMAKE_VERSION="${CMAKE_TAG#v}"
curl -fLO --progress-bar "https://github.com/Kitware/CMake/releases/download/$CMAKE_TAG/cmake-$CMAKE_VERSION.tar.gz"
#=#=#                                                                          
##O#-#                                                                         
#####                                                                     7.6%
################                                                         23.2%
###########################                                              38.8%
########################################                                 55.9%
###################################################                      71.3%
################################################################         90.1%
######################################################################## 100.0%

Extract and Enter the Source Directory

Extract the archive and switch into the source directory:

tar -xzf cmake-*.tar.gz
cd cmake-*

Bootstrap, Build, and Install

Run the bootstrap script to configure the build:

./bootstrap
-- Performing Test run_pic_test - Success
-- Performing Test run_inlines_hidden_test
-- Performing Test run_inlines_hidden_test - Success
-- Configuring done (13.9s)
-- Generating done (0.7s)
-- Build files have been written to: /root/cmake-src/cmake-4.2.1
---------------------------------------------
CMake has bootstrapped.  Now run gmake.

Compile CMake. The -j"$(nproc)" flag uses all available CPU cores to speed up the build:

make -j"$(nproc)"
[100%] Building CXX object Tests/CMakeLib/CMakeFiles/CMakeLibTests.dir/testDebuggerVariablesHelper.cxx.o
[100%] Building CXX object Tests/CMakeLib/CMakeFiles/CMakeLibTests.dir/testDebuggerVariablesManager.cxx.o
[100%] Building CXX object Tests/CMakeLib/CMakeFiles/CMakeLibTests.dir/testDebuggerThread.cxx.o
[100%] Linking CXX executable CMakeLibTests
[100%] Built target CMakeLibTests

Install the build to /usr/local:

sudo make install
-- Installing: /usr/local/share/cmake-4.2/Templates/AppleInfo.plist
-- Installing: /usr/local/share/vim/vimfiles/indent
-- Installing: /usr/local/share/vim/vimfiles/indent/cmake.vim
-- Installing: /usr/local/share/vim/vimfiles/syntax
-- Installing: /usr/local/share/vim/vimfiles/syntax/cmake.vim
-- Installing: /usr/local/share/emacs/site-lisp/cmake-mode.el
-- Installing: /usr/local/share/aclocal/cmake.m4
-- Installing: /usr/local/share/bash-completion/completions/cmake
-- Installing: /usr/local/share/bash-completion/completions/cpack
-- Installing: /usr/local/share/bash-completion/completions/ctest

Confirm the source build is the one in your PATH:

which cmake
cmake --version
/usr/local/bin/cmake
cmake version 4.2.1

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

Create an Update Script for Source Builds

Source builds do not update automatically, so create a small script that checks the latest tag and rebuilds only when needed. This script keeps your source build current without re-downloading when you are already up to date.

cat <<'EOF' > ~/cmake-src/update-cmake.sh
#!/bin/bash
set -e

INSTALL_PREFIX="/usr/local"
BUILD_DIR="$HOME/cmake-src"
REPO="Kitware/CMake"

# Use sudo only when needed.
SUDO="sudo"
if [ "$(id -u)" -eq 0 ]; then
  SUDO=""
fi

# Required tools for downloads and builds.
for cmd in curl tar make gcc g++; do
  if ! command -v "$cmd" >/dev/null 2>&1; then
    echo "Error: $cmd is required but not installed."
    echo "Run: $SUDO apt install build-essential curl"
    exit 1
  fi
done

# OpenSSL headers are required for the bootstrap step.
if ! dpkg -s libssl-dev >/dev/null 2>&1; then
  echo "Error: libssl-dev is required for the CMake bootstrap step."
  echo "Run: $SUDO apt install libssl-dev"
  exit 1
fi

mkdir -p "$BUILD_DIR"

# Detect the currently installed CMake version.
CURRENT_VERSION="$($INSTALL_PREFIX/bin/cmake --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n 1 || true)"
if [ -z "$CURRENT_VERSION" ]; then
  CURRENT_VERSION="$(cmake --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n 1 || true)"
fi
if [ -z "$CURRENT_VERSION" ]; then
  CURRENT_VERSION="none"
fi

# Fetch the latest tag from GitHub.
LATEST_TAG=$(curl -s https://api.github.com/repos/$REPO/tags | grep -oE '"name": "v[0-9]+\.[0-9]+\.[0-9]+"' | head -n 1 | cut -d '"' -f4)
if [ -z "$LATEST_TAG" ]; then
  echo "Error: Could not detect the latest CMake version from GitHub."
  exit 1
fi

LATEST_VERSION="${LATEST_TAG#v}"

echo "Current version: $CURRENT_VERSION"
echo "Latest version:  $LATEST_VERSION"

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

echo "Updating CMake to $LATEST_VERSION..."

cd "$BUILD_DIR"

# Clean old source trees.
rm -rf cmake-*

# Download, extract, build, and install.
curl -fLO --progress-bar "https://github.com/Kitware/CMake/releases/download/$LATEST_TAG/cmake-$LATEST_VERSION.tar.gz"
tar -xzf "cmake-$LATEST_VERSION.tar.gz"
rm -f "cmake-$LATEST_VERSION.tar.gz"

cd "cmake-$LATEST_VERSION"
./bootstrap
make -j"$(nproc)"
$SUDO make install

"$INSTALL_PREFIX/bin/cmake" --version | head -n 2
echo "Update complete."
EOF

Make the script executable:

chmod +x ~/cmake-src/update-cmake.sh

Run the script any time you want to check for updates:

~/cmake-src/update-cmake.sh
Current version: 4.2.1
Latest version:  4.2.1
CMake 4.2.1 is already up to date.

Testing Your CMake Installation

Verify that CMake can configure and build a simple project. If you do not already have a compiler, install the build tools first:

sudo apt install build-essential

Create a Test Project Directory

Create a dedicated directory for the test project to keep files organized:

mkdir -p ~/cmake-hello && cd ~/cmake-hello

Create the CMakeLists.txt File

Create the build configuration file:

nano CMakeLists.txt

Add the following configuration:

cmake_minimum_required(VERSION 3.16)
project(HelloWorld LANGUAGES CXX)
add_executable(hello main.cpp)
  • cmake_minimum_required: Ensures the CMake version meets the minimum required for the project.
  • project: Names the project and enables the C++ language.
  • add_executable: Defines the executable target and its source file.

Create the C++ Source File

Create the C++ source file:

nano main.cpp

Paste the following program:

#include <iostream>

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

Configure the Build

Generate build files in a separate build directory:

cmake -S . -B build
-- The CXX compiler identification is GNU 15.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (0.1s)
-- Generating done (0.0s)
-- Build files have been written to: /root/cmake-hello/build

Build the Program

Compile the project:

cmake --build build
[ 50%] Building CXX object CMakeFiles/hello.dir/main.cpp.o
[100%] Linking CXX executable hello
[100%] Built target hello

Run the Program

Run the compiled binary:

./build/hello
Hello, World!

Common Issues and Solutions

Bootstrap Fails with Missing OpenSSL Headers

If the bootstrap step cannot find OpenSSL, you will see errors like this:

-- Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR) 
CMake Error at Utilities/cmcurl/CMakeLists.txt:1001 (message):
  Could not find OpenSSL.  Install an OpenSSL development package or
  configure CMake with -DCMAKE_USE_OPENSSL=OFF to build without OpenSSL.

-- Configuring incomplete, errors occurred!
---------------------------------------------
Error when bootstrapping CMake:
Problem while running initial CMake
---------------------------------------------

Install the OpenSSL development package and run bootstrap again:

sudo apt install libssl-dev
./bootstrap
-- Configuring done (13.9s)
-- Generating done (0.7s)
-- Build files have been written to: /root/cmake-src/cmake-4.2.1
---------------------------------------------
CMake has bootstrapped.  Now run gmake.

CMake Cannot Find a C++ Compiler

If your system does not have a compiler installed, the configure step fails with output like:

-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:2 (project):
  No CMAKE_CXX_COMPILER could be found.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.


-- Configuring incomplete, errors occurred!

Install the compiler toolchain and rerun the configure step:

sudo apt install build-essential
cmake -S . -B build

Multiple CMake Versions in Your PATH

If you installed CMake from both APT and source, check which binary is used first in your PATH. The which command shows the active binary:

which cmake
APT install:
/usr/bin/cmake

Source install:
/usr/local/bin/cmake

To verify each version explicitly, run:

/usr/bin/cmake --version
/usr/local/bin/cmake --version

If you only want the source build, remove the APT package with sudo apt remove cmake.

Remove CMake

Use the removal steps that match the method you installed.

Remove the APT Package (Default or Kitware)

Remove the package and clean unused dependencies:

sudo apt remove cmake
sudo apt autoremove

Remove the Kitware Repository

Delete the repository file and keyring, then refresh APT:

sudo rm -f /etc/apt/sources.list.d/kitware.sources
sudo rm -f /usr/share/keyrings/kitware-archive-keyring.gpg
sudo apt remove kitware-archive-keyring
sudo apt update

Remove the Snap Package

Uninstall the snap:

sudo snap remove cmake

Remove a Source Build

Use the install_manifest.txt created by make install in your source tree:

cd ~/cmake-src/cmake-*
sudo xargs -a install_manifest.txt rm -f

Double-check the path before removing build directories. The command below deletes the entire CMake source tree from your home folder.

cd ~/cmake-src
rm -rf cmake-*

Conclusion

CMake is the standard build system generator for modern C and C++ projects, and Ubuntu gives you several solid ways to install it. Use the default APT package for stability, Kitware’s repository for newer releases on 24.04 and 22.04, Snap for isolated packaging, or a source build when you need the latest upstream tag and custom build options.

Useful CMake Links

Here are helpful upstream resources for learning and troubleshooting CMake:

2 thoughts on “How to Install CMake on Ubuntu (26.04, 24.04, 22.04)”

  1. Thank you for taking the time to reply to my previous comment. I just wanted to clarify that the files in this link: https://github.com/Kitware/CMake/releases, do not include the boostrap script and other files you mentioned. The instructions do work but I had to download the file from this link: https://cmake.org/download.

    I just thought that might be useful for others.

    Reply
    • Hi again Roberto,

      I am still at a loss how the GitHub download link did not show bootstrap and the other additional files, I downloaded Source code (tar.gz) yesterday and today and https://github.com/Kitware/CMake/archive/refs/tags/v3.28.2.tar.gz and it was in it and its exactly the same as the link on https://cmake.org/download.

      Regardless, if it works now that’s great and the main thing, I should put this down as the main download location as its more simple for just grabbing the source to compile, the GitHub page is good if you need a pacific source as it contains much more than the source if you want CMake via another option, but it can be confusing.

      Thanks for the feedback anyway.

      Reply

Leave a Comment

Let us know you are human: