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 OverflowCan 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.
How do I install CMake on CentOS?
You can install CMake on CentOS using the following steps:
- Open a terminal and update your system packages by using the following command: sudo yum update
- Install the CMake package by running the following command: sudo yum install cmake
- Verify the installation by running the following command: CMake –version
- This should display the version of CMake installed on your system.
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
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
Creating this symbolic link after installing cmake3 on Centos 7 worked for me:
sudo ln -s /usr/bin/cmake3 /usr/bin/cmake
rpm -Uv ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/Application:/Geo/CentOS_6/x86_64/cmake-3.0.0-143.1.x86_64.rpm
Hope this helps to somebody. If you have any problems with it let me know. Have fun.
I know this is an ancient question, but I got here by google searching and wanted to share what I knew so far.
when you sudo yum install cmake28, you get a /usr/bin/cmake28 binary on your machine. You can setup a symlink to make your configure script work via the following:
sudo ln -s /usr/bin/cmake28 /usr/bin/cmake
Not sure why the cmake28 package doesn't do this for you.
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
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:
Remove old version of cmake
sudo apt purge --auto-remove cmakeObtain 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/nullAdd 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/nullb. 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/nullc. 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/nullUpdate and install
sudo apt update sudo apt install cmake
Link: https://apt.kitware.com/