How to upgrade cmake in Ubuntu [duplicate]

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?


Solution 1:

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
    

Solution 2:

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

Solution 3:

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