120
CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
  CMake 3.6.0 or higher is required.  You are running version 3.5.1
-- Configuring incomplete, errors occurred!

I know Ubuntu uses stable releases that it can support, but some repos require later versions of cmake. I want to overwrite the old cmake with the later version of cmake, but the common PPA doesn't carry the cmake I need. How can I upgrade cmake to use the needed version without conflicts with the older version?

Wolf
  • 3,147

3 Answers3

158

Warning -- Do not do step 2 if you have Robot Operating System (ROS) installed

  1. Check your current version with:

    cmake --version
    
  2. Uninstall it with:

    sudo apt remove cmake
    
  3. Visit https://cmake.org/download/ and download the latest bash script.

    • In my case cmake-3.6.2-Linux-x86_64.sh is sufficient.
  4. Copy the script to /opt/.

  5. Make the script executable:

    chmod +x /opt/cmake-3.*your_version*.sh
    
  6. Change to desired installation directory (to /opt/ for example)

    • As of cmake 3.10.2 the installer no longer seems to install to /opt by default
  7. Run:

    sudo bash /opt/cmake-3.*your_version*.sh
    

    You will need to press y twice.

  8. The script installs the binary to /opt/cmake-3.*your_version* so in order to get the cmake command, make a symbolic link:

    sudo ln -s /opt/cmake-3.*your_version*/bin/* /usr/local/bin
    
  9. Test your results with:

    cmake --version
    
ignacio
  • 175
Wolf
  • 3,147
  • 8
    Don't think you need to uninstall the old cmake because /usr/local/bin is ahead of /usr/bin in PATH. So once you make the symlink in your last step, the cmake command will call your new cmake instead of the old one. – edwinksl Sep 25 '16 at 06:15
  • Yep, but based on what I read on other forums, most users would rather avoid the potential confusion – Wolf Sep 25 '16 at 06:27
  • 20
    As observed by Matt, IF YOU ARE A ROS USER DO NOT RUN "REMOVE CMAKE"

    Running this command will remove the current cmake version but will also remove parts of your ROS distribution, breaking everything and forcing you to re-install EVERYTHING related to ROS. A warning should be added to this command, or at the very least the leading answer should include a way to update cmake, rather than remove-and-replace.

    – sempaiscuba Jul 28 '17 at 00:18
  • 17
    ROS... "Robot Operating System"? – user1122069 Dec 04 '17 at 01:38
  • I'm running this in a container by script, so would I need to pass two "y"'s into the script? Are they planning on making cmake able to upgrade itself? – Timothy Swan Dec 25 '17 at 20:12
  • 12
    As of cmake 3.10.2 the installer no longer seems to install to /opt by default but rather to the current directory, so step 6 needs to be amended accordingly by the user. – JorgeGT Feb 14 '18 at 15:15
  • 7
    i did all that but once i type cmake --version it says command Cmake not found :( – DINA TAKLIT Oct 05 '18 at 12:09
  • @JorgeGT, what to do in this case? I got stuck on that step! cmd gives an errors -bash: /usr/bin/cmake: No such file or directory when typing cmake --version – smerllo Sep 20 '19 at 19:46
  • 3
    @Cs20 I had to do sudo ln -s /usr/local/bin/cmake /usr/bin/cmake on Ubuntu 16.04 for the same problem. – Kyle Falconer Oct 09 '19 at 23:17
  • 1
    and nobody explains what ROS is... – axd Nov 18 '19 at 22:25
  • It works for me on Windows Subsystem for Linux with CMake 3.16.4 – Matthieu H Feb 27 '20 at 18:48
  • 5
    Just in case someone else makes the same mistake : in the last step provide the full path of CMake binaries to the symbolic link. Otherwise bash still can't find the files. – yuqli Sep 26 '20 at 00:48
  • Actually, it will not be installed in /opt/ if you press "y" twice. Because the second "Y" is to confirm you want it to be installed in your home/user, inside a subfolder. So, symlink would point to there and not to /opt/ – mayid Oct 10 '20 at 19:09
  • 1
    @axd ROS is "Robot Operating System" https://www.ros.org – KansaiRobot May 21 '21 at 07:07
  • CMake 3.16 or higher is required. You are running version 3.5.1. Is that a joke? I am on Ubuntu 16.04 – bhordupur Jun 26 '21 at 19:46
  • @bhordupur No... 16 > 5. – Karu Aug 09 '21 at 01:46
  • 1
    For anybody reading down to here, I completely recommend this video on how to install the latest version of cmake in your linux system, without removing your previous version: https://youtu.be/_yFPO1ofyF0 . It works perfect, and the author of the video explains every step in detail. – jespestana Aug 26 '21 at 15:38
  • Tips for doing this with no problems: 1. use tab for completing /opt/cm ... TAB. 2. Don't forget / before /usr/local/bin – Gulzar Dec 15 '21 at 15:10
  • How can I automate pressing y twice? Trying to install in docker – Gulzar Dec 15 '21 at 15:23
  • @Gulzar You can install it with the flag "--skip-license " and it doesn't ask about license. – zupazt3 Jan 28 '22 at 19:10
  • 1
    cmake complained about not finding things when installed using this method. What worked for me was installing directly in /usr/local/ rather than installing in /opt/ and then creating links. The command would be sudo bash <path/to/script>/cmake<version>.sh --skip-license --exclude-subdir --prefix=/usr/local – John Apr 28 '22 at 21:42
  • I'm writing a Dockerfile to put cmake into it, the working directory is simply /, hence in step 8 I do sudo ln -s /cmake-3.*your_version*/bin/* /usr/local/bin. – kelvin hong 方 May 30 '22 at 07:55
61

In the new version of cmake (ex: 3.9.6), to install, download tar file from https://cmake.org/download/. Extract the downloaded tar file and then:

cd $CMAKE_DOWNLOAD_PATH
./configure
make
sudo make install
avazula
  • 165
  • 2
  • 12
ptphucbk
  • 711
  • 3
    I like this solution because it is arguably the purest way to solve the problem. (Just build the software.) No mucking around with PPAs or anything. Thanks! – Max von Hippel Jun 01 '20 at 04:09
  • 1
    This is a self-consistent solution. It works for me. – Yuanhui Jan 20 '21 at 08:55
  • I did this to update to 3.17 but after sudo make install I get this CMake Error: Could not find CMAKE_ROOT !!! CMake has most likely not been installed correctly. Modules directory not found in /usr/local/share/cmake-3.16 cmake version 3.16.3 – ChumbiChubaGo May 06 '21 at 20:26
  • 2
    First had to install OpenSSL to make it work: "sudo apt-get install libssl-dev" – Matt Jan 08 '22 at 19:11
  • solving : "Could not find CMAKE_ROOT" --> open new terminal (source bashrc), now run cmake --version – TripleS Nov 30 '23 at 11:19
2

I would like to follow your advice Wolf, but the script don't install the prog. So i just creat the folder but doesn't show like installed when i do

 cmake --version 

I find a other way peraps more easy :

sudo -E add-apt-repository -y ppa:george-edison55/cmake-3.x
sudo -E apt-get update
sudo apt-get install cmake
  • 6
    I tried this and it updated from 2.x to 3.2.2, but my build script still says "CMake 3.5.1 or higher is required." Is it possible to specify the add-apt-repository to be an even later version than 3.x, say something like "3.5.x" ? – Timothy Swan Dec 25 '17 at 20:09
  • 1
    Tis limited to version 3.5.2-2 while current distributes support 3.10.2 – Salem F Feb 26 '20 at 14:49