How to Install CMake on Ubuntu

Install CMake on Ubuntu with apt (3.31.6 on 25.04), Snap, Kitware binaries (.sh or .tar.gz), or a source build: check versions with apt-cache policy, use cmake -S -B for out-of-source builds, and avoid PATH conflicts between /usr/bin and /usr/local.

Published

Updated

Read time 8 min read

Reviewed byDeepak Prasad

Install CMake on Ubuntu banner with build gear icon and Ubuntu orange accent

CMake is the cross-platform build-system generator behind most modern C and C++ projects. It reads CMakeLists.txt files, detects compilers, and emits Makefiles or Ninja build files so you can run cmake --build instead of hand-writing compile rules. On Ubuntu you can install CMake from apt (simplest), Snap (often newer), official Kitware binaries, the Kitware apt repository, or a source build when you need a specific release.

This guide shows how to install CMake on Ubuntu, check which version your repositories offer, avoid the PATH mistakes that leave cmake “not found” after a manual download, and verify the install with a tiny out-of-source project. Commands below were run on Ubuntu 25.04; paths and package versions match current amd64 releases.

Tested on: Ubuntu 25.04 (Plucky Puffin); kernel 6.14.0-37-generic; amd64.

NOTE
Use one primary CMake install (apt, Snap, /usr/local, or /opt). Mixing apt cmake with a manual /usr/local/bin/cmake symlink often makes which cmake and cmake --version disagree. Remove the old package before switching (sudo apt purge cmake).

Quick command summary

Task Command
Check apt candidate apt-cache policy cmake
Install from Ubuntu repos sudo apt update && sudo apt install -y cmake
Install via Snap sudo snap install cmake --classic
Official .sh to /usr/local sudo sh cmake-*-linux-x86_64.sh --skip-license --exclude-subdir --prefix=/usr/local
Official .tar.gz under /opt sudo tar -xzf cmake-*-linux-x86_64.tar.gz -C /opt then extend PATH
Out-of-source configure cmake -S . -B build
Build cmake --build build
Optional GUI sudo apt install -y cmake-qt-gui
Remove apt package sudo apt purge -y cmake

Prerequisites

  • Ubuntu 22.04 LTS, 24.04 LTS, or newer (25.04 tested here) on x86_64 for the binary download filenames below.
  • sudo for system-wide installs.
  • build-essential (compiler toolchain) when you plan to compile CMake from source or build C++ projects after install—not required for apt install cmake alone.
  • Outbound HTTPS to archive.ubuntu.com, cmake.org, or github.com for binary and source downloads.

Choose an install method

Method Best for Typical version (2026)
apt install cmake Everyday development on Ubuntu 3.22–3.31 depending on LTS (3.31.6 on 25.04)
Snap (cmake) Newer upstream without compiling Tracks Snap Store releases (4.x)
Official .sh installer Specific Kitware build at /usr/local Latest from cmake.org/download
Official .tar.gz Portable tree under /opt without touching /usr/local Same as .sh, no installer prompts
Kitware apt repo apt workflow but newer than distro default Kitware-maintained packages
Source build Bleeding-edge or custom prefixes Whatever you compile

On Ubuntu 14.04/16.04, older guides suggested PPAs such as ppa:george-edison55/cmake-3.x or a separate cmake3 package. Modern Ubuntu ships cmake in main/universe with a current 3.x release—start with apt unless your CMakeLists.txt enforces a higher cmake_minimum_required.


Refresh indexes and inspect the candidate before installing:

bash
sudo apt update
apt-cache policy cmake

Example on Ubuntu 25.04:

text
cmake:
 Installed: (none)
 Candidate: 3.31.6-1ubuntu1
 Version table:
 3.31.6-1ubuntu1 500
 500 http://archive.ubuntu.com/ubuntu plucky/main amd64 Packages

Install with apt:

bash
sudo apt install -y cmake

The cmake package depends on cmake-data; you do not need a separate sudo apt install cmake-data step.

Verify:

bash
cmake --version
which cmake
dpkg -l cmake
text
cmake version 3.31.6

CMake suite maintained and supported by Kitware (kitware.com/cmake).
/usr/bin/cmake
ii cmake 3.31.6-1ubuntu1 amd64 cross-platform, open-source make system

When Ubuntu’s candidate is too old for your project, compare the required version in cmake_minimum_required(VERSION …) and move to Snap, Kitware binaries, or the Kitware apt repository.


Step 2: Install CMake from Snap

Canonical documents Snap installs at snapcraft.io/install/cmake/ubuntu. The cmake snap is published by Crascit (a CMake co-maintainer), not Kitware directly, but it tracks current upstream releases.

bash
sudo snap install cmake --classic

The --classic confinement flag is required so the build tool can read arbitrary project paths on disk.

Check the binary Snap exposes:

bash
snap run cmake --version
which cmake # often /snap/bin/cmake when Snap’s path precedes /usr/bin

On a host without Snap, apt install cmake already suggests:

text
sudo snap install cmake # version 4.3.4, or
sudo apt install cmake # version 3.31.6-1ubuntu1

Use Snap when you need CMake 4.x features while staying on an LTS release whose apt candidate is still 3.22–3.28. Remove the apt package first if both would provide /usr/bin/cmake.


Step 3: Install from the official .sh binary

Kitware publishes self-extracting cmake-VERSION-linux-x86_64.sh files on the download page. This matches the non-interactive pattern from Stack Overflow: specify where CMake is installed.

Remove apt CMake so modules and CMAKE_ROOT stay consistent:

bash
sudo apt purge -y cmake
sudo apt autoremove -y

Download a current release (example uses 4.3.4; pick the version your project needs):

bash
cd /tmp
wget https://github.com/Kitware/CMake/releases/download/v4.3.4/cmake-4.3.4-linux-x86_64.sh
chmod +x cmake-4.3.4-linux-x86_64.sh

Install into /usr/local without nested subdirectories or license prompts:

bash
sudo sh cmake-4.3.4-linux-x86_64.sh \
 --skip-license \
 --exclude-subdir \
 --prefix=/usr/local

Confirm:

bash
cmake --version
which cmake
text
cmake version 4.3.4
/usr/local/bin/cmake

/usr/local/bin is already on the default Ubuntu PATH, so you should not need to edit /etc/environment when you use --prefix=/usr/local as above.


Step 4: Install from the official .tar.gz binary

The .tar.gz distribution is a pre-built tree—the same layout the .sh installer extracts. Guides such as CGold CMake installation unpack it anywhere and extend PATH.

bash
cd /tmp
wget https://github.com/Kitware/CMake/releases/download/v4.3.4/cmake-4.3.4-linux-x86_64.tar.gz
sudo tar -xzf cmake-4.3.4-linux-x86_64.tar.gz -C /opt

Add the bin directory for your session:

bash
export PATH="/opt/cmake-4.3.4-linux-x86_64/bin:$PATH"
cmake --version

Persist the line in ~/.bashrc (or /etc/profile.d/cmake.sh for all users) when you want this layout permanently:

bash
echo 'export PATH="/opt/cmake-4.3.4-linux-x86_64/bin:$PATH"' >> ~/.bashrc

This method keeps Kitware’s files isolated under /opt and avoids overwriting /usr/bin/cmake from apt.


Step 5: Kitware apt repository (optional)

When you prefer deb packages but need a newer CMake than your Ubuntu release ships, Kitware maintains apt.kitware.com with signed repositories per distro codename. Follow their current instructions for adding the keyring and deb line, then:

bash
sudo apt update
sudo apt install cmake

This replaces the Ubuntu archive cmake candidate with Kitware’s build while staying on the apt upgrade path.


Step 6: Build CMake from source

Compile from source when you need a custom prefix, unreleased patches, or no pre-built binary for your platform. The workflow matches historical Ask Ubuntu and source-build notes—updated for current tarballs.

Install build dependencies (install OpenSSL on Ubuntu for libssl-dev):

bash
sudo apt update
sudo apt install -y build-essential libssl-dev

Download and bootstrap (example 4.3.4 source):

bash
cd /tmp
wget https://github.com/Kitware/CMake/releases/download/v4.3.4/cmake-4.3.4.tar.gz
tar -xzf cmake-4.3.4.tar.gz
cd cmake-4.3.4
./bootstrap
make -j"$(nproc)"
sudo make install

Default make install places cmake in /usr/local/bin. Re-open your shell or run hash -r before testing.

For a tracked .deb, some admins use checkinstall instead of make install; plain make install is enough on a single-user dev machine.


Optional: CMake GUI (cmake-gui)

Desktop users who want the graphical configurator can install the Qt front-end from Ubuntu:

bash
sudo apt install -y cmake-qt-gui
cmake-gui --version

Official .tar.gz / .sh bundles also ship cmake-gui in the same bin directory as the CLI.


Verify: minimal out-of-source project

After any install method, confirm CMake can configure and compile a trivial C++ target. Prefer out-of-source builds (cmake -S / cmake -B) over cmake . in the source tree.

bash
mkdir -p /tmp/cmake-hello && cd /tmp/cmake-hello
cat > CMakeLists.txt <<'EOF'
cmake_minimum_required(VERSION 3.10)
project(hello LANGUAGES CXX)
add_executable(hello main.cpp)
EOF
cat > main.cpp <<'EOF'
#include <iostream>
int main { std::cout << "CMake build OK\n"; }
EOF
cmake -S . -B build
cmake --build build
./build/hello

Example configure/build output on Ubuntu 25.04 with apt CMake:

text
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Configuring done (2.9s)
-- Generating done (0.0s)
-- Build files have been written to: /tmp/cmake-hello/build
[ 50%] Building CXX object CMakeFiles/hello.dir/main.cpp.o
[100%] Linking CXX executable hello
[100%] Built target hello
CMake build OK

Uninstall

APT:

bash
sudo apt purge -y cmake cmake-qt-gui
sudo apt autoremove -y

Snap:

bash
sudo snap remove cmake

Manual /usr/local or /opt install:

bash
sudo rm -f /usr/local/bin/cmake /usr/local/bin/ccmake /usr/local/bin/cmake-gui /usr/local/bin/ctest
sudo rm -rf /usr/local/share/cmake-*
sudo rm -rf /opt/cmake-*-linux-x86_64
# Remove any PATH lines you added to ~/.bashrc

Troubleshooting

Symptom Likely cause Fix
cmake: command not found after .sh download Extracted to $HOME without --prefix Re-run installer with --prefix=/usr/local --exclude-subdir --skip-license, or add bin to PATH
cmake --version shows old apt build /usr/bin before /usr/local on PATH which cmake; purge apt cmake or reorder PATH
CMAKE_ROOT / module errors after upgrade Mixed apt + manual files sudo apt purge cmake; remove /usr/local/share/cmake-*; reinstall one method
Project fails cmake_minimum_required Ubuntu apt too old Use Snap, Kitware binary, Kitware apt repo, or source build
cmake3 vs cmake confusion Legacy 14.04 docs On current Ubuntu install package cmake; cmake3 was transitional
PPA george-edison55/cmake-3.x missing Abandoned PPA Use apt, Snap, or official Kitware packages instead
Snap CMake cannot see host compilers Strict confinement Install with --classic as documented on Snapcraft

References


Summary

The fastest way to install CMake on Ubuntu is sudo apt install cmake: it pulls cmake-data, lands in /usr/bin/cmake, and on Ubuntu 25.04 provides 3.31.6. When projects require CMake 4.x or a specific Kitware release, use the Snap, the official .sh installer with --prefix=/usr/local --exclude-subdir --skip-license, a .tar.gz under /opt, the Kitware apt repository, or a source build.

Always verify with cmake --version, which cmake, and a small cmake -S . -B build project. Avoid stacking apt and manual installs, and skip obsolete cmake3/PPA workflows on current LTS releases unless you are maintaining legacy systems.

Frequently Asked Questions

1. How do I install CMake on Ubuntu?

Run sudo apt update && sudo apt install -y cmake on Ubuntu 16.04 and newer. The cmake package pulls in cmake-data automatically. Verify with cmake --version and which cmake (typically /usr/bin/cmake).

2. What version of CMake does Ubuntu apt install?

It depends on your release. Run apt-cache policy cmake before installing. On Ubuntu 25.04 the candidate is 3.31.6-1ubuntu1 from main; 22.04 LTS ships 3.22.x and 24.04 LTS ships 3.28.x.

3. How do I install the latest CMake on Ubuntu?

When apt is too old for your project, use the official Linux x86_64 .sh or .tar.gz from cmake.org/download, install the Snap (sudo snap install cmake --classic), add Kitware apt repository at apt.kitware.com, or compile from source. Do not rely on the obsolete ppa:george-edison55/cmake-3.x PPA.

4. How do I install CMake from the official .sh installer?

Download cmake-VERSION-linux-x86_64.sh, remove any apt cmake package first, then run sudo sh cmake-VERSION-linux-x86_64.sh --skip-license --exclude-subdir --prefix=/usr/local. Confirm with cmake --version.

5. Where is CMake installed on Ubuntu?

APT installs to /usr/bin/cmake with modules under /usr/share/cmake-*. Manual .sh installs with --prefix=/usr/local land in /usr/local/bin/cmake. Tarball extracts often live under /opt/cmake-VERSION-linux-x86_64/bin. Use which cmake to see which binary your shell resolves.

6. Why does Ubuntu say cmake is not installed after I downloaded the .sh file?

Extracting the installer in your home directory without --prefix does not update PATH. Either install with --prefix=/usr/local --exclude-subdir --skip-license, add the extracted bin directory to PATH in ~/.bashrc, or use apt/snap instead.

7. Should I use apt or Snap for CMake on Ubuntu?

apt is best for system packages and distro integration. Snap (maintained by Crascit, not Kitware directly) tracks newer upstream releases—useful when projects require CMake 4.x while your LTS apt candidate is still 3.22–3.28. Pick one channel to avoid version confusion.

8. How do I install CMake GUI on Ubuntu?

Install sudo apt install -y cmake-qt-gui alongside the cmake package, or use the cmake-gui binary from an official Kitware tarball. The GUI shares the same version as the CLI from that install method.

9. How do I uninstall CMake from Ubuntu?

For apt: sudo apt purge -y cmake cmake-qt-gui && sudo apt autoremove -y. For Snap: sudo snap remove cmake. For /usr/local installs: sudo rm -rf /usr/local/bin/cmake* /usr/local/share/cmake-* and remove tarball trees under /opt.

10. Do I need to install cmake-data separately?

No. sudo apt install cmake automatically installs the matching cmake-data package. Installing cmake-data alone does not provide the cmake executable.
Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive …