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. Ubuntu 24.04 LTS includes CMake 3.28.x and Ubuntu 22.04 LTS ships 3.22.x in the default repositories; for the latest upstream release (currently 4.2.x), use Kitware’s APT repository, Snap, or a source build.
This guide covers four installation methods, from default APT packages to compiling from source, with verification steps, an update script, and troubleshooting for common errors.
Install CMake on Ubuntu
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 give you full control over the version and build flags.
Default CMake versions differ across LTS releases:
| Ubuntu Release | Default CMake Version |
|---|---|
| Ubuntu 26.04 LTS | 3.31.x |
| Ubuntu 24.04 LTS | 3.28.x |
| Ubuntu 22.04 LTS | 3.22.x |
| Method | Channel | Version | Updates | Best For |
|---|---|---|---|---|
| APT (Default) | Ubuntu Packages | Stable (varies by release) | Automatic via APT | CI pipelines, stable builds |
| Kitware APT | apt.kitware.com | Latest (24.04/22.04 only) | Automatic via APT | Newer CMake without compiling |
| Snap | Snap Store | Latest stable | Automatic snap refresh | Isolated installs, all releases |
| Source | GitHub Releases | Any version | Manual rebuild | Custom build options, latest upstream |
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.
Pick one method below. Each section 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
This guide uses
sudofor commands that need root privileges. If your user is not in the sudoers file yet, follow the guide on how to add and manage sudo users on Ubuntu.
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 (currently CMake 4.x) 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
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.3-0kitware1ubuntu24.04.1
Version table:
4.2.3-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.3 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 a CMake co-maintainer 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.3 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.3 2026-01-28 (1515) 56MB classic latest/candidate: ^ latest/beta: ^ latest/edge: ^ 4.2/stable: 4.2.3 2026-01-28 (1515) 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 CMake getting started guide for additional build requirements.
Install CMake 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 CMake Source Archive
Use the curl command 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 -E '"name": "v[0-9]+\.[0-9]+\.[0-9]+"' | head -1 | 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 CMake Source Directory
Extract the archive and switch into the source directory:
tar -xzf cmake-*.tar.gz
cd cmake-*
Bootstrap, Build, and Install CMake
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.3 --------------------------------------------- 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.3 CMake suite maintained and supported by Kitware (kitware.com/cmake).
Create a CMake 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 -E '"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.3 Latest version: 4.2.3 CMake 4.2.3 is already up to date.
Test Your CMake Installation on Ubuntu
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 directory for the test project:
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 CMake 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 CMake Test 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 CMake Test Program
Run the compiled binary:
./build/hello
Hello, World!
Troubleshoot CMake on Ubuntu
CMake 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.3 --------------------------------------------- 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.
CMake Command Not Found on Ubuntu
If you see cmake: command not found after installing from source, the /usr/local/bin directory may not be in your shell’s PATH. Verify the binary exists and check your current PATH:
ls -l /usr/local/bin/cmake
echo $PATH
If /usr/local/bin is missing from the output, add it to your shell configuration:
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
cmake --version
For APT or Snap installs, the binary is placed in standard locations (/usr/bin/cmake or /snap/bin/cmake) that are already in PATH. If the command is still not found, confirm the package is installed with dpkg -l cmake or snap list cmake.
CMake Version Too Old for a Project
Some projects require a minimum CMake version. If you see an error like:
CMake 3.28 or higher is required. You are running version 3.22.1
Your default APT version is too old for that project. Switch to Kitware’s repository (Method 2) or install from source (Method 4) to get a newer version. On Ubuntu 22.04, the default CMake is 3.22.x, so projects targeting 3.28+ require one of these alternatives.
Remove CMake from Ubuntu
Use the removal steps that match the method you installed.
Remove the CMake APT Package (Default or Kitware)
Remove the package and clean unused dependencies:
sudo apt remove cmake
sudo apt autoremove
Verify the package is removed:
apt-cache policy cmake
Empty output confirms the package is no longer available from any configured repository. If you removed the Kitware repository (below), the package will not reappear in future updates.
Remove the Kitware CMake 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 CMake Snap Package
Uninstall the snap:
sudo snap remove cmake
Remove a CMake 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-*
Useful CMake Resources
These upstream resources cover CMake usage, configuration, and troubleshooting beyond installation:
- CMake Getting Started Guide – Official introduction to CMake basics and first projects.
- CMake Documentation – Complete command and module reference with examples.
- CMake Support Page – Paid and community support options from Kitware, with links to the Discourse forum.
- CMake GitHub Repository – Source code, releases, and issue tracking.
Frequently Asked Questions About CMake on Ubuntu
No. Ubuntu does not ship CMake pre-installed, but it is available in the default repositories. Run sudo apt install cmake to install it.
cmake is the standard command-line tool that generates build files. ccmake provides an interactive curses-based interface for configuring CMake projects in a terminal, and cmake-gui offers a graphical Qt-based configuration editor. Install them with sudo apt install cmake-curses-gui or sudo apt install cmake-qt-gui.
For APT installs (default or Kitware), run sudo apt update and sudo apt install --only-upgrade cmake. Snap updates automatically. For source builds, rerun the update script or download and compile the latest tag from GitHub.
Ubuntu’s default APT repositories package the CMake version available at the time of the distro release. Newer projects often set a minimum CMake version in their CMakeLists.txt that exceeds this default. Use Kitware’s APT repository, Snap, or a source build to get a newer version.
Conclusion
With CMake installed on Ubuntu, you can generate build files for Make, Ninja, and popular IDEs from a single CMakeLists.txt configuration. The default APT package handles most development work, Kitware’s repository delivers CMake 4.x on 24.04 and 22.04, Snap provides isolated packaging across all releases, and a source build gives full control over version and build flags. For production CI pipelines, pair CMake with GCC on Ubuntu to complete your toolchain.
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.
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.