I would like to install cmake the latest version, on Linux environment. I have cmake version 3.5 installed and is not supported by some applications. I tried to upgrade it by uninstalling the current version. But when I reinstall with sudo apt-get install cmake, I get the same version 3.5 re-installed. How do I install the latest version with sudo apt-get install ....?
-
2Get the targz and do `configure;make;make install`. https://cmake.org/files/v3.11/cmake-3.11.0.tar.gz – 123 Apr 16 '18 at 14:48
-
1I would like to preserve its install directory without having to build it with make install or anything manually. Is it possible to sudo apt-get latestversion....? – Juniar Apr 16 '18 at 14:57
-
@123 sudo apt-get ... might not be checking for cmake latest versions or anything current with this application... – Juniar Apr 16 '18 at 15:01
-
2Ubuntu 16.04 : `cmake-3.5.1` ... Ubuntu 17.10 : `cmake-3.9.1` ... Ubuntu 18.04 : `cmake-3.10.2` https://packages.ubuntu.com/search?keywords=cmake&searchon=names ... Later versions is a "build it yourself" job. – Knud Larsen Apr 16 '18 at 15:38
-
1@Knud Larsen That makes sense, but does it mean I have to install Ubuntu17.10 to get the latest cmake version? it might take longer that just installing cmake. – Juniar Apr 16 '18 at 15:43
11 Answers
As far as I know the best way to get the latest CMake version installed on any Linux is not by apt but using pip.
Remove the apt cmake and install the latest version from pip which can easily keep up-to-date.
apt remove cmake -y
pip install cmake --upgrade
-
Thanks for the info, However I was interested in knowing why sudo "apt" does not work on cmake and if this problem or error arise from cmake or apt, becoz that is not the case with other applications. That works fine with "sudo apt". Anyway I will try "pip" as my option. – Juniar Sep 16 '18 at 20:12
-
Check the answer below as now you can install CMake via apt-get maintained by the CMake official developer team. – Liu Hao Cheng Jun 23 '19 at 16:36
-
1Dear @LiuHaoCheng, your are right, but that works only for 16.04 and 18.04. – GNUton Jun 25 '19 at 22:06
-
@GNUton, They might not have tested the other versions too such as Ubuntu 17.10 etc. I would check for an update. – Juniar Jul 13 '19 at 16:50
-
3I used this to install cmake 3.13.3 on Ubuntu 18.04, but it didn't work out of the box: `"$ cmake .. CMake Error: Could not find CMAKE_ROOT !!! CMake has most likely not been installed correctly. Modules directory not found in /home/etienne/.local/share/cmake-3.12 CMake Error: Error executing cmake::LoadCache(). Aborting."` – Étienne Aug 08 '19 at 09:23
-
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_miroslav/cmake Storing debug log for failure in /home/miroslav/.pip/pip.log – Miroslav Avramov Jan 16 '20 at 12:13
-
4After that one must run sudo ln /usr/local/bin/cmake /usr/bin/cmake to create link to cmake executable – Alexey Antonenko Oct 07 '20 at 19:33
-
2It didn't work. After re installation gave me :bash: /usr/bin/cmake: No such file or directory. I think this is not the perfect solution. – MH.AI.eAgLe Sep 18 '21 at 06:54
-
it did remove cmake but failed to install the newest one and other things that depend on cmake messed up. – CroCo Dec 31 '22 at 04:03
-
This assumes you have `pip`, which is not true in a lot of Docker images. – Nike Jan 10 '23 at 18:12
-
Edit: As GNUton has pointed out, the following only works on Ubuntu. It supports 18.04, 20.04 and 22.04(Checked on March 2023).
Now CMake developer team in Kitware Inc provides APT repositiory. It allows you to install latest CMake via apt-get.
- If you are using a minimal Ubuntu image or a Docker image, you may need to install the following packages:
sudo apt-get update
sudo apt-get install gpg wget
- Obtain a copy of Kitware 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
- Add the repository to your sources list and 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
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
For Ubuntu Bionic Beaver (18.04):
echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ bionic main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null
- Install the kitware-archive-keyring package to ensure that your keyring stays up to date as Kitware rotate the keys:
sudo rm /usr/share/keyrings/kitware-archive-keyring.gpg
sudo apt-get install kitware-archive-keyring
Optional steps for subscription on release candidates. See details in reference.
Now call
sudo apt-get update
sudo apt-get install cmake
Have fun.
Reference: Kitware APT Repository.

- 669
- 6
- 6
-
I tried it and it work..., Onces I saw "Unpacking cmake (3.14.5-0kitware1) over (3.5.1-1ubuntu3) ...". so. Yes, You can now install the Latest cmake on any Ubuntu version, because I am running xenial and I have CMAKE 3.14.5. Indeed, this does avoid the build process if you can follow the guide provided, Thanks a lot! – Juniar Jun 21 '19 at 18:06
-
Follow the updated instructions on Kitware's website. Otherwise you'll get a warning message: `Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).` – ahogen Feb 20 '23 at 17:12
You can try the following steps that have worked for me on Ubuntu 18.04.3 LTS as OS of the NVIDIA jetson Nano to get the last version of cmake "cmake-3.14.0" from https://cmake.org/download/.
Delete the installed version in your system
sudo apt purge cmake
Download cmake3.13.4 source
wget https://github.com/Kitware/CMake/releases/download/v3.13.4/cmake-3.13.4.tar.gz
Extract files
tar zxvf cmake-3.13.4.tar.gz
Execute the following commands in this order to build it
cd cmake-3.13.4
sudo ./bootstrap
sudo make
sudo make install
Verify the version is installed correctly
cmake --version

- 20,575
- 8
- 83
- 77

- 427
- 4
- 5
Following the comments made on how to Install the latest CMake version and to post the answer for this question:
Ans:
This depends with Ubuntu OS version currently installed on your PC or Mac. If you have the following Ubuntu OS version then you have this CMake installed or that you could install and reinstall with "sudo apt-get install cmake". Even if you uninstall your version and try to reinstall later version.
Ubuntu 16.04 ships with cmake-3.5.1
Ubuntu 17.10 ships with cmake-3.9.1
Ubuntu 18.04 ships with cmake-3.10.2
Ubuntu 20.04 ships with cmake-3.16.3
Ubuntu 21.04 ships with cmake-3.18.4
Now if you have Ubuntu 16.04 installed and you want cmake-3.10, there is OS problem since you can only install and reinstalled cmake-3.5.1. To get cmake-3.10 or any other version, you have to download and install the package from https://packages.ubuntu.com/. Once you find the latest version of cmake .targz files, you have to build it yourself from the command line.

- 20,575
- 8
- 83
- 77

- 1,269
- 1
- 15
- 24
-
I have Ubuntu 18.04 and i need to install cmake-3.9.0 how to install after access to the link u shared – DINA TAKLIT Oct 05 '18 at 14:09
-
@ZINATAKLIT, Just run "sudo apt-get install cmake". This command will then search for cmake-3.10.2. You cannot install cmake-3.9.0 for your case, unless you have Ubuntu 17.10. You can also try running pip command, i.e "pip install cmake-x.x.x". Then check which version was installed. – Juniar Oct 05 '18 at 22:03
-
not sure how this really helps to install a newer CMake version for a defined ubuntu version. – GNUton Jun 25 '19 at 22:03
For CentOS/RHEL you can help these following steps:
yum -y install python-pip
pip install cmake --upgrade
If you are using Google Colab like me and wanted a higher version of cmake in it. Then do the following,
!pip uninstall cmake
!pip install cmake
This will install cmake 3.22 instead of the default version 3.12

- 21
- 1
pip install cmake --upgrade
if the following occurs after cmake .. :
CMake Error: Could not find CMAKE_ROOT !!!
CMake has most likely not been installed correctly.
Modules directory not found in
/.../.../...
CMake Error: Error executing cmake::LoadCache(). Aborting.
then try
hash -r
-
Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 20 '22 at 16:08
-
I could not find a way to also install the corresponding ccmake which makes cmake itself for me almost useless. – Fabian Nov 08 '22 at 23:26
the following worked for me:
sudo apt remove cmake
pip install cmake --upgrade
then, I exited the terminal and again entered to check the version with cmake --version
command

- 4,343
- 3
- 22
- 42
-
This is nearly a copy-paste of the current top-voted answer. If you have nothing additional to add to it, consider removing this answer. – aneroid Jan 26 '22 at 14:09
3.20.5 in ubuntu 16.04
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ xenial main' sudo apt update apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DE19EB17684BA42D sudo apt install cmake cmake-qt-gui cmake-curses-gui

- 57
- 4
yum remove cmake
wget https://github.com/Kitware/CMake/releases/download/v3.13.4/cmake-3.13.4.tar.gz
tar zxvf cmake-3.13.4.tar.gz
cd cmake-3.13.4
sudo ./bootstrap --prefix=/usr/local
sudo make
sudo make install
vi ~/.bash_profile
...
# PATH=$PATH:$HOME/bin
PATH=/usr/local/bin:$PATH:$HOME/bin
export PATH
source ~/.bash_profile
cmake --version
centos7 it help me

- 11
- 2
In case someone still finds it hard to remove cmake
from their machine.
This command works for me (requires sudo permissions):
$ sudo find / -name "cmake" | xargs -I % sudo rm -rf "%"

- 1,783
- 7
- 31
- 43
-
1Welcome to SO! Answers should be complete answers to the question. This doesn't show how to re-install. – starball Dec 17 '22 at 01:26