How To Install CMake on Ubuntu 26.04 LTS

Install CMake on Ubuntu 26.04

You cloned a promising C++ project from GitHub, ran make, and got hit with: cmake: command not found. That single error stops your entire workflow. To install CMake on Ubuntu 26.04 LTS, you have four solid options — and this guide walks you through all of them, with real terminal output and a clear explanation of why each step matters.

CMake is not a compiler. It is a cross-platform build system generator, developed and maintained by Kitware, that reads a single CMakeLists.txt file and produces native build instructions for Make, Ninja, or your IDE. Projects like LLVM, OpenCV, and Qt all depend on it.

Ubuntu 26.04 LTS ships CMake 3.31.x in its default APT repositories — a version that satisfies the requirements of most modern C++ projects right out of the box. If your project needs something newer, this guide also covers Snap (CMake 4.x) and building from source.

By the end, you will have CMake installed, verified, and tested against a real build project. You will also know how to troubleshoot the five most common errors and remove any installation cleanly.

Prerequisites

Before you touch a single command, confirm these items are in place. Skipping this step is the fastest way to hit confusing errors mid-install.

  • Ubuntu 26.04 LTS running on bare metal, a VM, or a cloud server
  • sudo privileges — verify with sudo whoami (should return root)
  • Active internet connection — required to download packages or source archives
  • A terminal session — SSH or local console both work fine
  • Optional for source builds: At least 2 GB of free disk space and a quad-core CPU to keep compile time reasonable

What Is CMake and Why Do You Need It?

Before diving into the How To Install CMake on Ubuntu 26.04 LTS steps, it helps to understand what CMake actually does under the hood.

CMake does not compile your code. It generates the instructions that your compiler toolchain uses to do that job. Every time you run cmake, it goes through three internal phases:

  1. Configure — reads your CMakeLists.txt, probes your system for compilers, libraries, and headers
  2. Generate — writes platform-specific build files (Makefiles, build.ninja, IDE project files)
  3. Build — calls Make or Ninja to compile and link your actual binaries

This three-step model is why CMake is the standard in cross-platform C/C++ development. One CMakeLists.txt works on Ubuntu, macOS, and Windows without rewriting a single line of build logic.

Choosing the Right Installation Method

Not every use case needs the same approach. Here is a quick decision matrix:

Method CMake Version on Ubuntu 26.04 Auto-Updates Best For
APT (Default) 3.31.6 Yes, via apt upgrade Most users, CI pipelines
Snap 4.2.3 (latest stable) Yes, via snap refresh Isolated installs, CMake 4.x
Source Build Any version (4.2.x+) Manual rebuild Custom flags, latest upstream
Binary .sh Installer Any version Manual Air-gapped servers

If you are a beginner or setting up a development server, start with Method 1. If a project’s CMakeLists.txt demands version 4.x or above, jump straight to Method 2 or Method 3.

One important warning: If you install CMake from both APT and source, you will end up with two binaries on your system at /usr/bin/cmake and /usr/local/bin/cmake. This causes PATH conflicts that produce hard-to-diagnose version mismatches. Pick one method and stick with it.

Step 1: Update Your System Package Index

Before installing anything on Ubuntu, refresh the local APT cache. This step applies regardless of which installation method you choose.

sudo apt update

WHY: APT stores package metadata in a local cache on your disk. That cache goes stale over time. If you skip this step, APT may try to install an outdated package version, or it may throw a “package not found” error even though the package exists in the Ubuntu repositories. One apt update takes under 10 seconds and prevents both problems.

Expected output:

Hit:1 http://archive.ubuntu.com/ubuntu resolute InRelease
Hit:2 http://security.ubuntu.com/ubuntu resolute-security InRelease
Reading package lists... Done

Step 2: Install CMake on Ubuntu 26.04 LTS via APT (Recommended)

This is the fastest and most stable method. It integrates with your system’s package manager, so CMake gets updated alongside everything else when you run apt upgrade.

Install the CMake Package

sudo apt install cmake -y

WHY: The -y flag skips the interactive confirmation prompt, which is useful when scripting server setups. APT automatically pulls in all required dependencies including cmake-data, libarchive13, and libjsoncpp25, so you do not need to install them manually.

Expected output:

Reading package lists... Done
Building dependency tree... Done
The following NEW packages will be installed:
  cmake cmake-data libarchive13 libjsoncpp25
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.

Verify the APT Installation

cmake --version

WHY: This confirms the cmake binary landed on your PATH at /usr/bin/cmake. If you see cmake: command not found here, the package failed to install — check your internet connection and re-run sudo apt update before trying again.

Expected output:

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

Install Optional GUI Tools

Two graphical tools ship alongside CMake and are worth knowing about:

sudo apt install cmake-curses-gui   # Installs ccmake: interactive terminal UI
sudo apt install cmake-qt-gui       # Installs cmake-gui: full graphical interface

WHY: ccmake lets you toggle build options interactively in the terminal without memorizing -DCMAKE_BUILD_TYPE=Release style flags. cmake-gui is invaluable when working with large projects like LLVM that expose 50+ configurable options. Neither is required for basic use.

Step 3: Install CMake via Snap (For CMake 4.x on Ubuntu 26.04)

If your project requires CMake 4.x, the Snap method delivers the latest stable release without you compiling anything. The CMake snap on the Snap Store is published by a CMake co-maintainer and updates automatically.

Confirm Snap Is Available

snap version

WHY: Ubuntu 26.04 ships with snapd enabled, but minimal server images and some containerized environments strip it out. Running snap version first prevents a confusing “snap: command not found” error later.

If the command returns nothing, install snapd:

sudo apt install snapd

Install CMake with Classic Confinement

sudo snap install cmake --classic

WHY: The --classic flag is not optional here. Without it, the snap runs in a strict sandbox that blocks CMake from reading your project’s source directories or writing to your build output folder — it would break every real-world build. Classic confinement grants the snap the same filesystem access as a standard binary.

Expected output:

cmake 4.2.3 from Crascit installed

Verify the Snap Installation

cmake --version
snap info cmake

WHY: snap info cmake shows available channels (latest/stable, 4.2/stable, latest/edge) so you can switch to a beta channel when testing new CMake features without affecting your stable install.

Expected output:

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

Step 4: Compile CMake from Source (Full Version Control)

This method takes longer but gives you the latest upstream release and full control over build flags. It works on every Ubuntu LTS release, including minimal server installations where Snap may not be available.

Install Build Dependencies

sudo apt install build-essential curl libssl-dev -y

WHY: Each package has a specific job here:

  • build-essential provides gcc, g++, and make — without these, the compiler toolchain does not exist and the bootstrap fails immediately
  • curl fetches the latest CMake release tag from GitHub’s API
  • libssl-dev provides OpenSSL headers required by CMake’s bootstrap script to compile its internal HTTPS client, used by file(DOWNLOAD) and ExternalProject — skipping this causes a “Could NOT find OpenSSL” error that halts the bootstrap

Download the Latest CMake Source

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 "https://github.com/Kitware/CMake/releases/download/$CMAKE_TAG/cmake-$CMAKE_VERSION.tar.gz"

WHY: Hardcoding a version number like v4.2.3 means this command goes stale the next time Kitware releases a patch. This one-liner queries the GitHub API for the latest tag dynamically, so the download is always current without editing anything.

Extract the Source Archive

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

WHY: tar -xzf decompresses the .tar.gz archive and unpacks all files. The wildcard cmake-* matches whatever version was downloaded, so you do not need to update this command when the version changes.

Run the Bootstrap Script

./bootstrap

WHY: The bootstrap is a self-contained shell script that compiles a minimal version of CMake using only a C compiler — no pre-existing CMake installation required. That minimal binary then configures the full CMake build. This is called bootstrapping: CMake uses itself to build itself, but it gets the first copy from scratch. The process takes roughly 60 to 90 seconds on a modern machine.

Expected output (end of bootstrap):

-- Configuring done (13.9s)
-- Generating done (0.7s)
-- Build files have been written to: /root/cmake-4.2.3
---------------------------------------------
CMake has bootstrapped. Now run gmake.

Compile Using All CPU Cores

make -j"$(nproc)"

WHY: $(nproc) returns the number of available CPU cores at runtime and passes it to the -j flag for parallel compilation. On a single-core VM this takes 10 to 15 minutes. On a four-core machine it drops to roughly three minutes. If you hard-code -j4 and run this on a two-core server, make will spawn more jobs than cores and thrash the system. $(nproc) adapts automatically.

Expected output (final lines):

[100%] Linking CXX executable CMakeLibTests
[100%] Built target CMakeLibTests

Install CMake System-Wide

sudo make install

WHY: This copies the compiled binaries to /usr/local/bin/ and supporting files to /usr/local/share/cmake-*/. Using /usr/local/ is intentional. It separates source-compiled software from APT-managed packages at /usr/, so your package manager never overwrites a source build — and a future apt upgrade cannot accidentally downgrade your CMake version.

Confirm the Source Build Is Active

which cmake
cmake --version

WHY: which cmake reveals which binary your shell resolves first. After a source install, you should see /usr/local/bin/cmake. If you see /usr/bin/cmake instead, an older APT-installed binary is shadowing your source build. Fix this by adding export PATH="/usr/local/bin:$PATH" to your ~/.bashrc and running source ~/.bashrc.

Expected output:

/usr/local/bin/cmake
cmake version 4.2.3
CMake suite maintained and supported by Kitware (kitware.com/cmake).

Step 5: Verify and Test Your CMake Installation

A passing cmake --version proves the binary exists. It does not prove CMake can actually configure and build a project. Run this quick test to confirm everything works end-to-end.

Create a Test Project

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

WHY: Isolating test files in a dedicated directory mirrors real-world project structure. It also makes cleanup simple — one rm -rf ~/cmake-hello removes everything.

Write the CMakeLists.txt

nano CMakeLists.txt

Paste this content:

cmake_minimum_required(VERSION 3.16)
project(HelloWorld LANGUAGES CXX)
add_executable(hello main.cpp)

WHY, line by line:

  • cmake_minimum_required(VERSION 3.16) — sets a minimum version floor. If someone runs your project on CMake 3.10, they get a clear error message instead of cryptic build failures
  • project(HelloWorld LANGUAGES CXX) — names the project and tells CMake to probe for a C++ compiler during the configure step
  • add_executable(hello main.cpp) — defines one build target named hello, compiled from main.cpp

Write the C++ Source File

nano main.cpp

Paste this content:

#include <iostream>

int main() {
    std::cout << "Hello, CMake on Ubuntu 26.04!" << std::endl;
    return 0;
}

Configure the Build

cmake -S . -B build

WHY: -S . tells CMake that the source directory is the current folder. -B build instructs CMake to write all generated files into a build/ subdirectory instead of polluting your source tree. This out-of-source build pattern keeps your working directory clean and lets you maintain separate Debug and Release configurations in parallel by using different -B targets.

Expected output:

-- The CXX compiler identification is GNU 15.2.0
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features - done
-- Configuring done (0.1s)
-- Generating done (0.0s)
-- Build files have been written to: /root/cmake-hello/build

Build and Run the Project

cmake --build build
./build/hello

Expected output:

[ 50%] Building CXX object CMakeFiles/hello.dir/main.cpp.o
[100%] Linking CXX executable hello
[100%] Built target hello
Hello, CMake on Ubuntu 26.04!

If you see that final line, CMake is fully operational on your system.

Step 6: How to Update CMake on Ubuntu 26.04

Keeping CMake current matters because many projects set a cmake_minimum_required value that tracks recent releases. Here is how to update based on your install method.

Update via APT

sudo apt update && sudo apt install --only-upgrade cmake

WHY: Using --only-upgrade upgrades CMake without touching any other packages. Running a bare sudo apt upgrade would upgrade everything on your system, which can cause unintended changes on production servers.

Update via Snap

Snap handles updates automatically in the background. To force an immediate check:

sudo snap refresh cmake

WHY: Snap’s auto-refresh daemon runs on a schedule (typically four times per day). If you need the newest CMake before the next scheduled refresh — for example, a project just updated its minimum required version — forcing a manual refresh pulls it instantly.

Update a Source Build

For source builds, save this update script to avoid repeating every step manually:

cat > ~/update-cmake.sh << 'EOF'
#!/bin/bash
set -e
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}"
INSTALLED=$(cmake --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
if [ "$INSTALLED" = "$CMAKE_VERSION" ]; then
  echo "CMake $INSTALLED is already up to date."
  exit 0
fi
echo "Updating from $INSTALLED to $CMAKE_VERSION..."
mkdir -p ~/cmake-src && cd ~/cmake-src
curl -fLO "https://github.com/Kitware/CMake/releases/download/$CMAKE_TAG/cmake-$CMAKE_VERSION.tar.gz"
tar -xzf cmake-*.tar.gz
cd cmake-*/
./bootstrap
make -j"$(nproc)"
sudo make install
echo "Done. $(cmake --version | head -1)"
EOF
chmod +x ~/update-cmake.sh

Run it any time:

~/update-cmake.sh

WHY: The version check at the top of the script avoids re-downloading and recompiling when you are already on the latest release. On a slow connection or low-powered server, this saves 10 to 15 minutes of unnecessary work.

Troubleshooting Common CMake Errors on Ubuntu 26.04

Error: cmake: command not found

Cause: After a source install, /usr/local/bin is missing from your shell’s PATH.

Fix:

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

For APT installs, confirm the package is actually installed:

dpkg -l cmake

For Snap installs, confirm the snap is present:

snap list cmake

Error: Could NOT find OpenSSL (Source Build)

Cause: libssl-dev was not installed before running ./bootstrap.

Fix:

sudo apt install libssl-dev
./bootstrap

You do not need to re-download the source archive — just re-run bootstrap from inside the extracted source directory.

Error: No CMAKE_CXX_COMPILER could be found

Cause: No C++ compiler is installed on the system.

Fix:

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

WHY: CMake probes for a C++ compiler during the configure step. If g++ is absent, the probe fails and CMake cannot proceed. build-essential installs gcc, g++, and make in one command.

Error: CMake 3.28 or higher is required

Cause: This error only appears if someone is running an older Ubuntu release where the default CMake is below 3.28. On Ubuntu 26.04, you have 3.31.6 — which clears this requirement.

If you somehow see this on 26.04, the project needs CMake 4.x. Switch to Snap:

sudo snap install cmake --classic

Error: Two CMake Versions Conflicting

Cause: Both APT and a source-compiled CMake are installed, creating two binaries at /usr/bin/cmake and /usr/local/bin/cmake.

Diagnosis:

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

To remove the APT version:

sudo apt remove cmake

To remove a source build precisely:

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

WHY: install_manifest.txt is generated by sudo make install and records every file placed on your system. Using it for removal is surgical — it deletes exactly what was installed and nothing else.

How to Uninstall CMake from Ubuntu 26.04

When you need to switch methods or clean up a test environment, use the removal command that matches your install method.

APT:

sudo apt remove cmake && sudo apt autoremove

autoremove cleans up orphaned packages like cmake-data that APT pulled in as dependencies.

Snap:

sudo snap remove cmake

Source build:

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

Congratulations! You have successfully installed CMake. Thanks for using this tutorial for installing CMake on the Ubuntu 26.04 LTS (Resolute Raccoon) system. For additional help or useful information, we recommend you check the official CMake website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!
r00t is a Linux Systems Administrator and open-source advocate with over ten years of hands-on experience in server infrastructure, system hardening, and performance tuning. Having worked across distributions such as Debian, Arch, RHEL, and Ubuntu, he brings real-world depth to every article published on this blog. r00t writes to bridge the gap between complex sysadmin concepts and practical, everyday application — whether you are configuring your first server or optimizing a production environment. Based in New York, US, he is a firm believer that knowledge, like open-source software, is best when shared freely.

Related Posts