Once you have both the cmake and the cmake3 package installed on your machine, you can use update-alternatives to switch between both packages.

Use the alternatives command to register both installations:

$ sudo alternatives --install /usr/local/bin/cmake cmake /usr/bin/cmake 10 \
--slave /usr/local/bin/ctest ctest /usr/bin/ctest \
--slave /usr/local/bin/cpack cpack /usr/bin/cpack \
--slave /usr/local/bin/ccmake ccmake /usr/bin/ccmake \
--family cmake

$ sudo alternatives --install /usr/local/bin/cmake cmake /usr/bin/cmake3 20 \
--slave /usr/local/bin/ctest ctest /usr/bin/ctest3 \
--slave /usr/local/bin/cpack cpack /usr/bin/cpack3 \
--slave /usr/local/bin/ccmake ccmake /usr/bin/ccmake3 \
--family cmake

After these two commands, cmake3 will be invoked by default, when you enter cmake from a bash prompt or start a bash script. The commands also take care of registering a few secondary commands like ctest which need to be switched along with cmake.

If you need to switch back to cmake 2.8 as the default, run the following command:

$ sudo alternatives --config cmake

There are 2 programs which provide 'cmake'.

  Selection    Command
-----------------------------------------------
   1           cmake (/usr/bin/cmake)
*+ 2           cmake (/usr/bin/cmake3)

Enter to keep the current selection[+], or type selection number: 1
Answer from sakra on Stack Overflow
🌐
GitHub
gist.github.com › zrsmithson › 8a1b7923a8f37dcb2e6b12b7e408fd50
Installing latest cmake and git versions on Rhel/Centos, and setting it as the default commands · GitHub
... For this, we will install the ... install curl-devel expat-devel gettext-devel openssl-devel zlib-devel sudo yum install gcc perl-ExtUtils-MakeMaker...
🌐
GitHub
gist.github.com › 1duo › 38af1abd68a2c7fe5087532ab968574e
Install CMake on CentOS 7. - Gist - GitHub
Your current cmake might still linked to the previous installation. ... Worked as expected in RHEL 7. Although I didn't install the default version (with yum install cmake etc.) at all.
🌐
VPSie
vpsie.com › home › how to's tutorials › how to install cmake on centos 8
How To Install CMake on CentOS 8 | VPSie Tutorials
March 19, 2023 - # sudo yum updateinfo · Run the command if it is available, # sudo dnf update · Here’s how we install the latest version of CMake: To obtain the source code, type the following command: # wget https://github.com/Kitware/CMake/releases/d...
People also ask

Can I install CMake from source on CentOS?

Yes, you can install CMake from the source on CentOS. However, using the package manager to install CMake is recommended, as it will manage dependencies and updates automatically.

🌐
vpsie.com
vpsie.com › home › how to's tutorials › how to install cmake on centos 8
How To Install CMake on CentOS 8 | VPSie Tutorials
How do I install CMake on CentOS?

You can install CMake on CentOS using the following steps:

  1. Open a terminal and update your system packages by using the following command: sudo yum update
  2. Install the CMake package by running the following command: sudo yum install cmake
  3. Verify the installation by running the following command: CMake –version
  4. This should display the version of CMake installed on your system.
🌐
vpsie.com
vpsie.com › home › how to's tutorials › how to install cmake on centos 8
How To Install CMake on CentOS 8 | VPSie Tutorials
What are the dependencies required to install CMake on CentOS?

The dependencies required to install CMake on CentOS are:

  • GCC (GNU Compiler Collection)
  • Make
  • ncurses-devel
  • zlib-devel
  • curl-devel
🌐
vpsie.com
vpsie.com › home › how to's tutorials › how to install cmake on centos 8
How To Install CMake on CentOS 8 | VPSie Tutorials
🌐
OS Radar
osradar.com › home › linux › how to install cmake on centos 8
How To Install CMake On CentOS 8 - Linux Windows and android Tutorials
June 11, 2020 - To do so hit the below listed commands. sudo yum install epel-release · sudo yum install snapd · sudo systemctl enable --now snapd.socket · sudo ln -s /var/lib/snapd/snap /snap ·
🌐
Snapcraft
snapcraft.io › install › cmake › centos
Install CMake on CentOS using the Snap Store | Snapcraft
September 30, 2025 - Get the latest version of CMake for on CentOS - Cross-platform software build system generator
🌐
Cheaphosting
clientarea.cheaphosting.pk › knowledgebase › 103 › How-to-Install-Latest-CMake-on-CentOS.html
How to Install Latest CMake on CentOS? - Support Articles - CheapHosting.Pk
Enter the following commands on the terminal to upgrade PHP: 1 . To install the latest... g++: error: unrecognized command line option '-std=c++14' make: *** [src/core/ext/filters/census/grpc_context.lo] Error 1 ERROR: `make' failed · For CentOS run this. # yum install gcc-c++ Then Install cmake.
Find elsewhere
🌐
idroot
idroot.us › home › how to install cmake on centos 8
How To Install CMake on CentOS 8 - idroot
August 6, 2024 - Snap is a universal package manager that works across many Linux distributions, including CentOS 8. To install CMake using Snap: sudo yum install epel-release sudo yum install snapd sudo systemctl enable --now snapd.socket sudo ln -s ...
🌐
CMake
cmake.org › download
Download CMake
You can either download binaries or source code archives for the latest stable or previous release or access the current development (aka nightly) distribution through Git. This software may not be exported in violation of any U.S. export laws or regulations. For more information regarding Export Control matters, please visit our Legal page. The release was packaged with CPack which is included as part of the release. The .sh files are self extracting gziped tar files. To install a .sh file, run it with /bin/sh and follow the directions.
🌐
CMake
cmake.org › install
Resources
February 22, 2023 - Whether you are still learning how to use CMake, contributing, or just enjoy being part of the conversation, there is is something here for everyone. ... Stay up to date with the latest CMake blog articles and software releases.
🌐
LinuxVox
linuxvox.com › blog › how-to-install-cmake-on-linux
How to Install CMake on Linux: A Comprehensive Guide — linuxvox.com
# For CentOS sudo yum install cmake # For Fedora sudo dnf install cmake · If you need the latest version of CMake or the package manager version is too old, you can compile CMake from source.
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_developer_tools › 1 › html › using_llvm_14.0.6_toolset › assembly_llvm
Chapter 1. LLVM Toolset | Using LLVM 14.0.6 Toolset | Red Hat Developer Tools | 1 | Red Hat Documentation
To install the cmake-doc package, run the following command: On Red Hat Enterprise Linux 7: # yum install llvm-toolset-14.0-cmake-doc · You can find the documentation under the following path: opt/rh/llvm-toolset-14.0/root/usr/share/doc/llvm-toolset-14.0-cmake-3.6.2/html/cmake.html.
🌐
Contradodigital
yum-info.contradodigital.com › view-package › epel › cmake3
About cmake3 for Yum on Linux
This command will update cmake3 to the latest version. When you run this command with the -y flag, you will not be prompted to check that you are sure you want to remove the package - so be sure you absolutely want to remove cmake3 when using the -y flag. ... This command will show you core information about the cmake3 package. ... This command will show you the dependencies for cmake3. Thankfully, when using Yum, if dependencies are required, these are also installed at the same time so you don't have to worry too much about that.
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/

🌐
Bluhm-de
bluhm-de.com › home › linux › compile cmake on centos 7
Compile CMAKE on CentOS 7
This guide will tell you, how to quickly install it. So far, it has been tested with CMAKE 3.13.1 · CMAKE_VERSION=3.13.1 cd /tmp yum -y install gcc-c++ wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}.tar.gz tar xf cmake*.tar.gz cd cmake* ./bootstrap ...
🌐
Snapcraft
snapcraft.io › install › cmake › rhel
Install CMake on Red Hat Enterprise Linux using the Snap Store | Snapcraft
April 21, 2026 - Get the latest version of CMake for on Red Hat Enterprise Linux - Cross-platform software build system generator
🌐
Contradodigital
yum-info.contradodigital.com › view-package › base › cmake
About cmake for Yum on Linux
This command will update cmake to the latest version. When you run this command with the -y flag, you will not be prompted to check that you are sure you want to remove the package - so be sure you absolutely want to remove cmake when using the -y flag. ... This command will show you core information about the cmake package. ... This command will show you the dependencies for cmake. Thankfully, when using Yum, if dependencies are required, these are also installed ...
🌐
SourceExample
sourceexample.com › article › en › 68a27e3315ce3e52c7074e044b7969ff
Centos install the latest version of cmake
July 27, 2020 - yum remove cmake ln -s /usr/local/bin/cmake /usr/bin/cmake cmake --version · Now that the installation is complete, the installation of cmake is relatively simple, the following are the problems encountered during the installation process:
🌐
DirectAdmin
docs.directadmin.com › operation-system-level › os-general › package-management.html
Package management | DirectAdmin Docs
We recommend trying to use your system's package manager to install cmake on your system: bash · yum install cmake · bash · apt-get install cmake · Extracting mysql-5.6.29.tar.gz ...