The most common situation is when you want to install the latest version of cmake, but your Operating System's repositories are not updated. For example, in my case I have a laptop running Ubuntu 16.04, and when I executed the command sudo apt install cmake the installed version was 3.5.1; instead of 4.0.3 which is the current version at cmake.org.

Teo, how can I get the latest version?

Well, we can install it by following one of these methods:

  • Using APT Repositories
  • Building and Installing from source
  • Using binary files

A. Using APT Repositories (Recommended for normal users)

Kitware now provides an [APT Repository][4] that supports Ubuntu 24.04, 22.04, and 20.04. So we can install it easily following these steps:

A-1. Uninstall the default version provided by Ubuntu's package manager and configuration by using:

sudo apt remove --purge --auto-remove cmake

or:

sudo apt purge --auto-remove cmake

A-2. If you are using a minimal Ubuntu image or a Docker image, you may need to install the following packages:

sudo apt update
sudo apt install ca-certificates gpg wget

A-3. If the kitware-archive-keyring package has not been installed previously, manually obtain a copy of our signing key:

test -f /usr/share/doc/kitware-archive-keyring/copyright ||
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null

A-4. Add kitware's repository to your sources list and update.

For Ubuntu Noble Numbat (24.04):

echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ noble main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null
sudo apt update

For Ubuntu Jammy Jellyfish (22.04):

echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ jammy main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null
sudo apt update

For Ubuntu Focal Fossa (20.04):

echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ focal main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null
sudo apt update

A-5. If the kitware-archive-keyring package has not been installed previously, remove the manually obtained signed key to make room for the package:

test -f /usr/share/doc/kitware-archive-keyring/copyright ||
sudo rm /usr/share/keyrings/kitware-archive-keyring.gpg

A-6. Install the kitware-archive-keyring package to ensure that your keyring stays up to date as we rotate our keys:

sudo apt install kitware-archive-keyring

A-7. Finally we can install the cmake package.

sudo apt update
sudo apt install cmake

B. Building and Installing (Recommended for developers)

For this approach you need to install the GCC tools:

sudo apt update
sudo apt install build-essential libtool autoconf unzip wget

B-1. Uninstall the default version provided by Ubuntu's package manager as in A-1.

B-2. Go to the official CMake webpage, then download and extract the latest version. Update the version and build variables in the following command to get the desired version:

version=4.0
build=3
## don't modify from here
mkdir ~/temp
cd ~/temp
wget https://cmake.org/files/v$version/cmake-$version.$build.tar.gz
tar -xzvf cmake-$version.$build.tar.gz
cd cmake-$version.$build/

B-3. Install the extracted source by running:

./bootstrap
make -j$(nproc)
sudo make install

B-4. Test your new cmake version.

$ cmake --version

Results of cmake --version:

cmake version 4.0.X

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

C. Using binary files (cmake-gui might not work well)

C-1. Uninstall the default version provided by Ubuntu's package manager as in A-1.

C-2. Go to the official CMake webpage, then download and install the latest .sh version in opt/cmake. Update the version and build variables in the following command to get the desired version:

version=4.0
build=3
## don't modify from here
limit=3.20
result=$(echo "$version >= $limit" | bc -l)
os=$([ "$result" == 1 ] && echo "linux" || echo "Linux")
mkdir ~/temp
cd ~/temp
wget https://cmake.org/files/v$version/cmake-$version.$build-$os-x86_64.sh 
sudo mkdir /opt/cmake
sudo sh cmake-$version.$build-$os-x86_64.sh --prefix=/opt/cmake

C-3. Add the installed binary link to /usr/local/bin/cmake by running this:

sudo ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake

C-4. Test your new cmake version as in B-4.

Note

In 4.0.X the X represents the last part of the version that we defined as build. The build may change if cmake is updated. According to the official web page the Latest Release is 4.0.3. If you want the Previous Release 3.31.6 just replace the version and build parameters like this:

version=3.31
build=6
## don't modify from here
limit=3.20
result=$(echo "$version >= $limit" | bc -l)
os=$([ "$result" == 1 ] && echo "linux" || echo "Linux")
mkdir ~/temp
cd ~/temp
wget https://cmake.org/files/v$version/cmake-$version.$build-$os-x86_64.sh 
sudo mkdir /opt/cmake
sudo sh cmake-$version.$build-$os-x86_64.sh --prefix=/opt/cmake

Observation

For previous versions of CMake (3.19.7 <=), remember that the file name contains an upper case L in -Linux-x86_64.sh and from version 3.20 it has a lower case l in -linux-x86_64.sh

Answer from Teocci on askubuntu.com
🌐
CMake
cmake.org β€Ί cmake β€Ί help β€Ί latest β€Ί command β€Ί install.html
install β€” CMake 4.4.0-rc1 Documentation
As absolute paths do not work with the cmake --install command's --prefix option, or with the cpack installer generators, it is strongly recommended to use relative paths throughout for best support by package maintainers.
Top answer
1 of 13
483

The most common situation is when you want to install the latest version of cmake, but your Operating System's repositories are not updated. For example, in my case I have a laptop running Ubuntu 16.04, and when I executed the command sudo apt install cmake the installed version was 3.5.1; instead of 4.0.3 which is the current version at cmake.org.

Teo, how can I get the latest version?

Well, we can install it by following one of these methods:

  • Using APT Repositories
  • Building and Installing from source
  • Using binary files

A. Using APT Repositories (Recommended for normal users)

Kitware now provides an [APT Repository][4] that supports Ubuntu 24.04, 22.04, and 20.04. So we can install it easily following these steps:

A-1. Uninstall the default version provided by Ubuntu's package manager and configuration by using:

sudo apt remove --purge --auto-remove cmake

or:

sudo apt purge --auto-remove cmake

A-2. If you are using a minimal Ubuntu image or a Docker image, you may need to install the following packages:

sudo apt update
sudo apt install ca-certificates gpg wget

A-3. If the kitware-archive-keyring package has not been installed previously, manually obtain a copy of our signing key:

test -f /usr/share/doc/kitware-archive-keyring/copyright ||
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null

A-4. Add kitware's repository to your sources list and update.

For Ubuntu Noble Numbat (24.04):

echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ noble main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null
sudo apt update

For Ubuntu Jammy Jellyfish (22.04):

echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ jammy main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null
sudo apt update

For Ubuntu Focal Fossa (20.04):

echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ focal main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null
sudo apt update

A-5. If the kitware-archive-keyring package has not been installed previously, remove the manually obtained signed key to make room for the package:

test -f /usr/share/doc/kitware-archive-keyring/copyright ||
sudo rm /usr/share/keyrings/kitware-archive-keyring.gpg

A-6. Install the kitware-archive-keyring package to ensure that your keyring stays up to date as we rotate our keys:

sudo apt install kitware-archive-keyring

A-7. Finally we can install the cmake package.

sudo apt update
sudo apt install cmake

B. Building and Installing (Recommended for developers)

For this approach you need to install the GCC tools:

sudo apt update
sudo apt install build-essential libtool autoconf unzip wget

B-1. Uninstall the default version provided by Ubuntu's package manager as in A-1.

B-2. Go to the official CMake webpage, then download and extract the latest version. Update the version and build variables in the following command to get the desired version:

version=4.0
build=3
## don't modify from here
mkdir ~/temp
cd ~/temp
wget https://cmake.org/files/v$version/cmake-$version.$build.tar.gz
tar -xzvf cmake-$version.$build.tar.gz
cd cmake-$version.$build/

B-3. Install the extracted source by running:

./bootstrap
make -j$(nproc)
sudo make install

B-4. Test your new cmake version.

$ cmake --version

Results of cmake --version:

cmake version 4.0.X

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

C. Using binary files (cmake-gui might not work well)

C-1. Uninstall the default version provided by Ubuntu's package manager as in A-1.

C-2. Go to the official CMake webpage, then download and install the latest .sh version in opt/cmake. Update the version and build variables in the following command to get the desired version:

version=4.0
build=3
## don't modify from here
limit=3.20
result=$(echo "$version >= $limit" | bc -l)
os=$([ "$result" == 1 ] && echo "linux" || echo "Linux")
mkdir ~/temp
cd ~/temp
wget https://cmake.org/files/v$version/cmake-$version.$build-$os-x86_64.sh 
sudo mkdir /opt/cmake
sudo sh cmake-$version.$build-$os-x86_64.sh --prefix=/opt/cmake

C-3. Add the installed binary link to /usr/local/bin/cmake by running this:

sudo ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake

C-4. Test your new cmake version as in B-4.

Note

In 4.0.X the X represents the last part of the version that we defined as build. The build may change if cmake is updated. According to the official web page the Latest Release is 4.0.3. If you want the Previous Release 3.31.6 just replace the version and build parameters like this:

version=3.31
build=6
## don't modify from here
limit=3.20
result=$(echo "$version >= $limit" | bc -l)
os=$([ "$result" == 1 ] && echo "linux" || echo "Linux")
mkdir ~/temp
cd ~/temp
wget https://cmake.org/files/v$version/cmake-$version.$build-$os-x86_64.sh 
sudo mkdir /opt/cmake
sudo sh cmake-$version.$build-$os-x86_64.sh --prefix=/opt/cmake

Observation

For previous versions of CMake (3.19.7 <=), remember that the file name contains an upper case L in -Linux-x86_64.sh and from version 3.20 it has a lower case l in -linux-x86_64.sh

2 of 13
113

Kitware now has an APT repository that currently supports 20.04, 22.04 and 24.04.

All repos support AMD64, ARM32, ARM64 architectures

Install Instructions:

  1. Remove old version of cmake

     sudo apt purge --auto-remove cmake
    
  2. Obtain a copy of the signing key

     wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null
    
  3. Add the repository to your sources list

    a. For Ubuntu Noble Numbat (24.04)

     echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ noble main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null
    

    b. For Ubuntu Jammy Jellyfish (22.04)

     echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ jammy main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null
    

    c. For Ubuntu Focal Fossa (20.04)

     echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ focal-rc main' | sudo tee -a /etc/apt/sources.list.d/kitware.list >/dev/null    
    
  4. Update and install

     sudo apt update
     sudo apt install cmake
    

Link: https://apt.kitware.com/

🌐
CMake
cmake.org β€Ί cmake β€Ί help β€Ί latest β€Ί guide β€Ί tutorial β€Ί Installing and Testing.html
Step 5: Installing and Testing β€” CMake 4.3.3 Documentation
This page was once part of an older version of the CMake tutorial which last appeared in CMake 4.1. See the current tutorial version here Β· To see the older version, follow this link or select the drop-down in the page header
🌐
CMake
cmake.org β€Ί cmake β€Ί help β€Ί v3.13 β€Ί command β€Ί install.html
install β€” CMake 3.13.5 Documentation
The install() command generates a file, cmake_install.cmake, inside the build directory, which is used internally by the generated install target and by CPack. You can also invoke this script manually with cmake -P.
🌐
CMake Discourse
discourse.cmake.org β€Ί development
What is the intended use case of the install command line option? - Development - CMake Discourse
January 5, 2020 - What is the intended use case of the cmake --install command line option (or the older install target)? I am wondering because it seems extremely cumbersome and hard to customize compared to CPack. The documentation states: CMake provides a command-line signature to install an already-generated ...
Find elsewhere
🌐
StudyPlan.dev
studyplan.dev β€Ί cmake β€Ί setting-up-a-cmake-environment
How to Install and Configure CMake on Windows, macOS, and Linux
July 27, 2025 - Learn how to install and set up your CMake environment on Windows, macOS, and Linux. This guide covers installation, using the command line vs. the GUI, IDE integration (Visual Studio, VS Code, CLion), and configuring compilers like MSVC and GCC.
🌐
CMake
cmake.org β€Ί cmake β€Ί help β€Ί v3.8 β€Ί command β€Ί install.html
install β€” CMake 3.8.2 Documentation
There are multiple signatures for this command. Some of them define installation options for files and targets. Options common to multiple signatures are covered here but they are valid only for signatures that specify them. The common options are: ... Specify the directory on disk to which a file will be installed. If a full path (with a leading slash or drive letter) is given it is used directly. If a relative path is given it is interpreted relative to the value of the CMAKE_INSTALL_PREFIX variable.
🌐
CMake
cmake.org β€Ί cmake β€Ί help β€Ί v3.0 β€Ί command β€Ί install.html
install β€” CMake 3.0.2 Documentation
There are multiple signatures for this command. Some of them define installation options for files and targets. Options common to multiple signatures are covered here but they are valid only for signatures that specify them. The common options are: ... Specify the directory on disk to which a file will be installed. If a full path (with a leading slash or drive letter) is given it is used directly. If a relative path is given it is interpreted relative to the value of the CMAKE_INSTALL_PREFIX variable.
🌐
CMake
cmake.org β€Ί cmake β€Ί help β€Ί book β€Ί mastering-cmake β€Ί chapter β€Ί Install.html
Installing Files β€” Mastering CMake
This command is invoked by a project ... actual installation of files. For Makefile generators (UNIX, NMake, MinGW, etc.), the user simply runs make install (or nmake install) and the make tool will invoke CMake’s installation module....
🌐
CMake
cmake.org β€Ί install
Resources
February 22, 2023 - All the resources you need to begin your CMake journey, from learning materials to accessing the CMake community.
🌐
JetBrains
jetbrains.com β€Ί help β€Ί clion β€Ί using-cmake-install.html
CMake install | CLion Documentation
April 8, 2024 - Set up the installation paths via the [DESTINATION dir] field of the install command. Here you have two options: Provide the full path with a leading slash or drive letter. Use a relative path, which will be interpreted as relative to the value of the CMAKE_INSTALL_PREFIX variable, if provided in the CMake options section of the Settings | Build, Execution, Deployment | CMake dialog:
🌐
CMake
cmake.org β€Ί cmake β€Ί help β€Ί v3.2 β€Ί command β€Ί install.html
install β€” CMake 3.2.3 Documentation
There are multiple signatures for this command. Some of them define installation options for files and targets. Options common to multiple signatures are covered here but they are valid only for signatures that specify them. The common options are: ... Specify the directory on disk to which a file will be installed. If a full path (with a leading slash or drive letter) is given it is used directly. If a relative path is given it is interpreted relative to the value of the CMAKE_INSTALL_PREFIX variable.
🌐
CMake
cmake.org β€Ί cmake β€Ί help β€Ί v4.1 β€Ί guide β€Ί tutorial β€Ί Installing and Testing.html
Step 5: Installing and Testing β€” CMake 4.1.5 Documentation
Then, run the install step by using the --install option of the cmake command (introduced in 3.15, older versions of CMake must use make install) from the command line. This step will install the appropriate header files, libraries, and executables.
Top answer
1 of 4
21

You have to think of your folder structures as an "Interface". Then there are three interfaces:

  1. source interface
  2. build interface
  3. install interface

Each interface has a different folder structure with different files in it. The install interface is just the folder structure you get by installing with CMake. Essentially, it takes all your relevant files lying around in your build folder and creates a nice folder structure which other projects can use.

Typically, in an out-of-source build (what is best practice), your source interface will be a subfolder of your project root, e.g., src or source. You then typically configure, generate and build your lib to a directory build which lives right next to src so that your project structure looks like this:

Source and build interfaces:

project_root
β”œβ”€β”€ CMakeLists.txt
β”œβ”€β”€ src
β”‚   └── CMakeLists.txt
β”œβ”€β”€ build
β”‚   └── CMakeCache.txt
...

So that covers the source and build interfaces. But what about the install interface? Answer: The install interface goes wherever the user wants it to go to. The location is specified by CMAKE_INSTALL_PREFIX. You can override it by specifying the --prefix argument:

cmake --install . --prefix "/where/I/want/it/to/go"

This would create the install interface according to the install()-rules you declared in your CMakeLists.txt. For example, if using a default layout using GNUInstallDirs (highly recommended even for windows), this would create a folder structure under /where/I/want/it/to/go/project_root like so:

Install interface:

project_root
β”œβ”€β”€ bin
β”‚   └── executables
β”œβ”€β”€ sbin
β”‚   └── sysadmin executables
β”œβ”€β”€ lib
β”‚   β”œβ”€β”€ compiled libraries (*.so (unix) or *.dll (windows))
β”‚   └── library archive files (*.lib (windows))
β”œβ”€β”€ libexec
β”‚   └── executables not directly invoked by user
β”œβ”€β”€ include
β”‚   └── header files
β”œβ”€β”€ doc
β”‚   └── documentation

You can see that almost all of the nonsense that we used for developing has vanished and we're left with a pure directory that contains mostly precompiled stuff that other applications can use. You would use the install interface of a project B if your project depends on B and you know that it's going to be installed on Windows or Linux platforms. The install interface is typically not of much use when developing for embedded systems that only run minimal operating systems or none at all, in this case you would build your whole application using the source interface of project B by including it in your project and add it using add_subdirectory().

2 of 4
5

INSTALL is useful in, at least, two scenarios:

  • You download some package's source code, generate the binaries, which you want to use in your system. You can INSTALL them under /usr/bin, for example

  • You compile some library which you'll use from another product. It will gather the required files (header files, libraries...), and just those, and put them in a known place, no matter where the library compilation expects them.

You could just copy them, but relying on CMake allows the process to be expressed at a higher level.