135

Default cmake version of 14.04 is 2.8. How can I install cmake 3.2 and replace the default one? Or how can I upgrade 2.8 to 3.2?

Xetra
  • 121
  • 4
ycshao
  • 1,481
  • 2
  • 10
  • 5
  • 2
    Be aware that some system-installed packages will not work correctly with cmake 3.2 on 14.04. For example Eigen installs its CMake modules in /usr/share/cmake-2.8, where they obviously can't be found by CMake 3.2. – Martin Pecka Dec 12 '16 at 13:50

8 Answers8

204

Either use a PPA or compile it yourself:

  1. Installation by a PPA (Upgrade to 3.2)

    sudo apt-get install software-properties-common
    sudo add-apt-repository ppa:george-edison55/cmake-3.x
    sudo apt-get update
    
    • When cmake is not yet installed:

      sudo apt-get install cmake
      
    • When cmake is already installed:

      sudo apt-get upgrade
      
  2. Compile it yourself

    Currently, the latest version is 3.2.2, the following instructions based on this version. You should therefore check this URL and adjust the file name accordingly.

    sudo apt-get install build-essential
    wget http://www.cmake.org/files/v3.2/cmake-3.2.2.tar.gz
    tar xf cmake-3.2.2.tar.gz
    cd cmake-3.2.2
    ./configure
    make
    

    Now you can have to choose an installation type to decide, I recommend installing with checkinstall, as this creates a DEB package.

    • With checkinstall

      sudo apt-get install checkinstall
      sudo checkinstall
      
    • With make install

      sudo make install
      
A.B.
  • 89,123
  • 21
  • 245
  • 323
  • 10
    The first method doesn't work for me. I run both install or upgrade and both are no-op for me. Install from source works, and I like the approach to install as .deb package. – ycshao Apr 20 '15 at 01:59
  • 15
    Yeah, the first method doesn't work for me either. – weberc2 Sep 01 '15 at 16:19
  • Method 1 doesn't work and I had to purge the cmake package to get back to a working cmake (2.8) by reinstalling. Method 2 works fine. – user2746401 Sep 04 '15 at 12:31
  • 3
    Method 1 did not initially work for me (it installed, but cmake did not work correctly due to things like CMAKE_ROOT not being found), but after purging the cmake package (as well as cmake-data just in case) and then reinstalling 3.2 through apt-get it worked fine. – JAB Sep 09 '15 at 20:01
  • Oh, and if you don't have `add-apt-repository` (I didn't, assumedly because I was installing on a slimmed-down VM), you need to install the `software-properties-common` package. – JAB Sep 09 '15 at 21:12
  • @JAB which package you had to purge? ,`cmake`? – A.B. Sep 10 '15 at 04:57
  • @JAB thank you for the comment. I've added the command to install `software-properties-common` – A.B. Sep 10 '15 at 04:58
  • @A.B. I purged both `cmake` and `cmake-data`; I didn't experiment individually to see if only one actually needed to be purged. I had a similar issue on another Ubuntu distro where I manually installed CMake 3.3.1 in /usr/local; I assumed both the package installation and manual installation could exist simultaneously, but doing so left the CMake configuration in an inconsistent state and I had to purge the package install. It may have had something to do with paths determined by some configuration file somewhere that the cmake executable checks, but I didn't feel like digging deeply into it. – JAB Sep 10 '15 at 13:32
  • apt-get upgrade did not work for me; apt-get remove cmake, apt-get install cmake did – gerardw Mar 09 '16 at 16:18
  • For the first method, run `sudo apt-get dist-upgrade` to install cmake 3.x. Otherwise, the cmake package will be held back and only cmake-data will be installed. – Anthony Apr 23 '16 at 19:58
  • Just a side-note for anyone who is building OpenCV 3 from source and has a problem with `cmake` not finding the Python libraries for 2.7 and/or 3.0 even though the `dev` packages are installed - this fixes the issue! – rbaleksandar May 29 '16 at 15:20
  • For step 2, where should I be doing this? /user/home/ or /usr/src/ or what? If either, which is better? Thanks for your very clear answer. – Elliptical view Oct 24 '16 at 21:20
  • Copy-pasted `sudo apt-get upgrade` ( `cmake` absent) and got all my other packages upgraded, except `cmake`... – Jānis Elmeris Mar 12 '17 at 07:48
  • PPA did not work. – Dagrooms Jun 06 '17 at 13:57
  • I was having to do the purge method as others indicated, I was going to use this method https://stackoverflow.com/questions/18615451/cmake-missing-modules-directory, but it was going to have me uninstall a lot of packages I need. #2 works. – adamconkey Aug 26 '17 at 21:24
  • On ubuntu 16.04, simply `sudo apt-get install cmake` works well ! – Eric Mar 20 '18 at 02:18
  • If you are getting `CMake Error: Could not find CMAKE_ROOT !!!`, uninstall then reinstall `cmake` and `cmake-data`: https://stackoverflow.com/questions/18615451/cmake-missing-modules-directory – Vladimir Panteleev May 07 '18 at 23:33
  • This only works if I use `apt-get install cmake3` (note the 3 at the end). – Richard Fairhurst Oct 18 '18 at 09:44
  • Linux raised a security error on first method – Samuel Owino Feb 23 '19 at 22:09
  • And the authenticity of this PPA repository? "george-edison55"? – Zoran Pavlovic Sep 24 '19 at 16:56
  • @ZoranPavlovic It's like any foreign repository you use. Either you trust or you don't. – A.B. Sep 26 '19 at 07:27
38

There are three options:

  • install from a PPA
  • install the pre-built binary distribution from cmake.org
  • compile it yourself

Installation from PPA

sudo add-apt-repository ppa:george-edison55/cmake-3.x
sudo apt-get update

When cmake is not already installed:

sudo apt-get install cmake

When cmake is already installed:

sudo apt-get upgrade

Installation from cmake.org binary distrubtion

curl -sSL https://cmake.org/files/v3.5/cmake-3.5.2-Linux-x86_64.tar.gz | sudo tar -xzC /opt

CMake executables will be in /opt/cmake-3.5.2-Linux-x86_64/bin/.

Compile it yourself

Currently, the latest version is 3.5.2, the following instructions based on this version. You should therefore check the download page and adjust the file name accordingly.

sudo apt-get install build-essential
wget http://www.cmake.org/files/v3.5/cmake-3.5.2.tar.gz
tar xf cmake-3.5.2.tar.gz
cd cmake-3.5.2
./configure
make

Now you can have to choose an installation type to decide, I recommend installing with checkinstall, as this creates a DEB package.

  • with checkinstall

    sudo apt-get install checkinstall
    sudo checkinstall
    
  • with make install

    sudo make install
    
David Foerster
  • 35,754
  • 55
  • 92
  • 145
nocnokneo
  • 363
  • 4
  • 7
  • 3
    It adds a "Installation from cmake.org binary distrubtion" option. Also improves the formatting and bumps the cmake download URL to the newest release. I tried to just edit the accepted answer but my edits where not accepted by the author. – nocnokneo Aug 27 '15 at 20:53
14

I am not sure if I am late to the party, but recently on Ubuntu 14.04 I faced same issues and this is how I got it solved. First, you need to remove the existing cmake by executing the command:

sudo apt-get remove cmake

Hit return or enter. Next, you need to install cmake3 by using the following commands:

sudo apt-get update 

sudo apt-get upgrade 

sudo apt-get install cmake3

Assuming, my answer will get old in few years, consider searching for a cmake package that has a number associated with it. For example, at this time, cmake3 works for me.

To do so, all you have to execute is

apt-cache search cmake

Once you find the package, just install as suggested.

Thank you
Happy Coding!

Fennec
  • 241
  • 3
  • 5
8

Try to build it from source, install it and adjust your $PATH variables to make it available. Maybe you should add the exported variables to your bashrc. That is basically how I would do it, please change file and folder names to your needs:

sudo apt-get install build-essential
wget http://url.to/cmake-3.2-src.tar.gz
tar xzf cmake-3.2-src.tar.gz
cd cmake-3.2-src
./configure
make
# If make finishes without errors:
sudo make install
export PATH=/usr/local/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
cmake --version # This should give v3.2
Oliver R.
  • 377
  • 2
  • 11
4

For Ubuntu 20.04 LTS simply run:

sudo apt install cmake
Izaya
  • 221
  • 3
  • 8
1

Try:

sudo snap install cmake --classic
Eliah Kagan
  • 116,445
  • 54
  • 318
  • 493
Hrithik Raj
  • 61
  • 1
  • 2
1

Just install the latest from the sh from https://cmake.org/download/

cd /usr
sudo wget https://cmake.org/files/v3.8/cmake-3.8.2-Linux-x86_64.sh -P /usr/
sudo chmod 755 /usr/cmake-3.8.2-Linux-x86_64.sh
sudo ./cmake-3.8.2-Linux-x86_64.sh
Gun2sh
  • 111
  • 2
0

For me, all I needed was:

apt-get -y install cmake

I found that info here.

stevec
  • 113
  • 3