Upgrading cmake in Ubuntu 14.04

Lets imagine we need to compile some C++ library and get error telling that newer version of cmake is required. For instance, I had cmake v2.8 but version larger than 3.1 was required.

Compile cmake from source

$ sudo su

And compile it

# apt-get update
# apt-get dist-upgrade
# cd /Downloads
/Downloads# wget https://cmake.org/files/v3.5/cmake-3.5.0-rc1.tar.gz
/Downloads# tar xzf cmake-3.5.0-rc1.tar.gz
/Downloads# cd cmake-3.5.0-rc1
/Downloads/cmake-3.5.0-rc1#

Rename the existing installation directory to the new version where, “x.x” is the existing installation directory and “3.5” will be the new name. We will also want to install a compiler (if you haven’t already done so) and a few other tools.

# mv /usr/share/cmake-x.x /usr/share/cmake-3.5
# apt-get install build-essential checkinstall
# apt-get install cvs subversion git-core mercurial

Some additional actions with user permissions

# sudo chown $USER /usr/local/src
# sudo chmod u+rwx /usr/local/src

Now we need to instruct the install script, what to do and where to do it. Specify the path we just created

# ./configure --prefix=/usr/share/cmake-3.5

This will bootstrap all the files within the cmake source directory and builds them so that they can be compiled. Then make it

# make

And finish things off by installing.

# make install

Check the installation

# /usr/share/cmake-3.5/bin/cmake -version

Set CMAKE_ROOT to pointing to our new installation path so we can call cmake from any location

export CMAKE_ROOT=/usr/share/cmake-3.5

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store