How to Install the Latest Version of CMake on Ubuntu 16.04/18.04 Linux

This post will guide you how to download and install the latest stable version of CMake on your Ubuntu Linux server. How do I install CMake tool from source code on Ubuntu Linux 16.04/18.04. How to install CMake from binary distrubtion on Ubuntu system.

What is CMake?


CMake is a cross-platform free and open-source software application for managing the build process of software using a compiler-independent method. It supports directory hierarchies and applications that depend on multiple libraries. CMake can be used to build, test, and package software on your system.

CMake can be used to control the software compilation process to geneate a native build environment that will compile source code, create libraries, generate wrappers and build executables in arbitray combinations.

ubuntu install cmake1

Installing CMake from Default Ubuntu Repo


CMake package is available in the default Ubuntu 16.04 or 18.04 repository (it may be a older version of CMake), so you can use apt install command to install it directlry, type:

$ sudo apt update
$ sudo apt install cmake

Outputs:

devops@devops-osetc:~$ sudo apt install cmake
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
augeas-lenses cpu-checker cryptsetup cryptsetup-bin db-util db5.3-util dmeventd extlinux hfsplus icoutils ipxe-qemu ipxe-qemu-256k-compat-efi-roms ldmtool libafflib0v5 libaugeas0 libbfio1
libcacard0 libconfig9 libdate-manip-perl libdevmapper-event1.02.1 libewf2 libfdt1 libhfsp0 libhivex0 libintl-perl libintl-xs-perl libiscsi7 libldm-1.0-0 liblvm2app2.2 liblvm2cmd2.02
librados2 librbd1 libsdl1.2debian libspice-server1 libssl-doc libstring-shellquote-perl libsys-virt-perl libtsk13 libusbredirparser1 libvirt0 libwin-hivex-perl libxen-4.9 libxenstore3.0
lsscsi lvm2 msr-tools osinfo-db qemu-block-extra qemu-system-common qemu-system-x86 qemu-utils scrub seabios sgabios sleuthkit supermin zerofree
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
cmake-data libjsoncpp1 librhash0
Suggested packages:
cmake-doc ninja-build
The following NEW packages will be installed:
cmake cmake-data libjsoncpp1 librhash0
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/4,621 kB of archives.
After this operation, 24.5 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Selecting previously unselected package cmake-data.
(Reading database ... 225780 files and directories currently installed.)
Preparing to unpack .../cmake-data_3.10.2-1ubuntu2_all.deb ...
Unpacking cmake-data (3.10.2-1ubuntu2) ...
Selecting previously unselected package libjsoncpp1:amd64.
Preparing to unpack .../libjsoncpp1_1.7.4-3_amd64.deb ...
Unpacking libjsoncpp1:amd64 (1.7.4-3) ...
Selecting previously unselected package librhash0:amd64.
Preparing to unpack .../librhash0_1.3.6-2_amd64.deb ...
Unpacking librhash0:amd64 (1.3.6-2) ...
Selecting previously unselected package cmake.
Preparing to unpack .../cmake_3.10.2-1ubuntu2_amd64.deb ...
Unpacking cmake (3.10.2-1ubuntu2) ...
Setting up cmake-data (3.10.2-1ubuntu2) ...
Setting up librhash0:amd64 (1.3.6-2) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Setting up libjsoncpp1:amd64 (1.7.4-3) ...
Setting up cmake (3.10.2-1ubuntu2) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...

After installed, you can try to verify CMake version to check if it is successfully installed on your system, type:

$ cmake --version

Outputs:

devops@devops-osetc:~$ cmake --version
cmake version 3.10.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).

From the above outputs you can see, the installed version of cmake is 3.10.2. You can go to the official download web page of CMake to see that the latest stable version of CMake is 3.13.4.

Installing CMake from PPA on Ubuntu 16.04


If you are using Ubuntu 16.04 system, you can also use a PPA repository to install CMake tool on your system with the following commands:

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

Outputs:

If CMake is alreay installed on your Ubuntu system, you can use apt upgrade command to upgrade CMake to the latest version, type:

$ sudo apt upgrade

Or you can add the following entries into /etc/apt/sources.list file:

deb http://ppa.launchpad.net/george-edison55/cmake-3.x/ubuntu xenial main
deb-src http://ppa.launchpad.net/george-edison55/cmake-3.x/ubuntu xenial main

Next, run the following command to update Package manager cache, type:

$ sudo apt update

Then, install CMake tool using this PPA with the following command:

$ sudo apt install cmake

Installing CMake from Binary Distrubtion


You should know that the above two methods is not able to install the latest statble version (now the latest version is 3.13.4) of CMake. You can go to the official CMake webpage to download the latest version of CMake binary distrubtion file.

The Binary Distrubtion of CMake have two file extention, one is shell script, and another is archive file. The below will show you how to use those two files to install CMake.

For Shell Binary Distrubtion of CMake:

#1 Downloading CMake Bianary file with the following wget command:

$ wget https://github.com/Kitware/CMake/releases/download/v3.13.4/cmake-3.13.4-Linux-x86_64.sh

Outputs:

devops@devops-osetc:~$ wget https://github.com/Kitware/CMake/releases/download/v3.13.4/cmake-3.13.4-Linux-x86_64.sh
--2019-02-28 06:38:15-- https://github.com/Kitware/CMake/releases/download/v3.13.4/cmake-3.13.4-Linux-x86_64.sh
Resolving www-proxy.us.osetc.com (www-proxy.us.osetc.com)... 148.87.19.20
Connecting to www-proxy.us.osetc.com (www-proxy.us.osetc.com)|148.87.19.20|:80... connected.
Proxy request sent, awaiting response... 302 Found
Location: https://github-production-release-asset-2e65be.s3.amazonaws.com/537699/9069a980-2625-11e9-995f-c14527390cc5?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20190314%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190314T085210Z&X-Amz-Expires=300&X-Amz-Signature=0587e2cad2fdd3bc101e3527b081e2e2612fd6a2fb098a013c1ad3365b02516b&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Dcmake-3.13.4-Linux-x86_64.sh&response-content-type=application%2Foctet-stream [following]
--2019-02-28 06:38:16-- https://github-production-release-asset-2e65be.s3.amazonaws.com/537699/9069a980-2625-11e9-995f-c14527390cc5?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20190314%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190314T085210Z&X-Amz-Expires=300&X-Amz-Signature=0587e2cad2fdd3bc101e3527b081e2e2612fd6a2fb098a013c1ad3365b02516b&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Dcmake-3.13.4-Linux-x86_64.sh&response-content-type=application%2Foctet-stream
Connecting to www-proxy.us.osetc.com (www-proxy.us.osetc.com)|148.87.19.20|:80... connected.
Proxy request sent, awaiting response... 200 OK
Length: 38410590 (37M) [application/octet-stream]
Saving to: ‘cmake-3.13.4-Linux-x86_64.sh’

cmake-3.13.4-Linux-x86_64.sh 100%[==========================================================================>] 36.63M 420KB/s in 91s

2019-02-28 06:39:48 (413 KB/s) - ‘cmake-3.13.4-Linux-x86_64.sh’ saved [38410590/38410590]

#2 After intalled CMake Binary file, just execute it:

$ sh cmake-3.13.4-Linux-x86_64.sh

Outputs:

devops@devops-osetc:~$ sh cmake-3.13.4-Linux-x86_64.sh
CMake Installer Version: 3.13.4, Copyright (c) Kitware
This is a self-extracting archive.
The archive will be extracted to: /home/devops

If you want to stop extracting, please press <ctrl-C>.
CMake - Cross Platform Makefile Generator
Copyright 2000-2018 Kitware, Inc. and Contributors
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
......
Do you accept the license? [yN]:y
By default the CMake will be installed in:
"/home/devops/cmake-3.13.4-Linux-x86_64"
Do you want to include the subdirectory cmake-3.13.4-Linux-x86_64?
Saying no will install in: "/home/devops" [Yn]:Y
Y

Using target directory: /home/devops/cmake-3.13.4-Linux-x86_64
Extracting, please wait...

Unpacking finished successfully

Note: you need to press y key on your keyboard to accept the license to continue the installation process. You also need to specify one target directory, if you type Y key, it will use the default setting to install CMake in the current directory.

#3 you need to change the current directory to ./cmake-3.13.4-Linux-x86_64/bin/, and all of CMake executables are located here.

$ cd ./cmake-3.13.4-Linux-x86_64/bin/
$ ./cmake --version

Outputs:

devops@devops-osetc:~/cmake-3.13.4-Linux-x86_64/bin$ ./cmake --version
cmake version 3.13.4

CMake suite maintained and supported by Kitware (kitware.com/cmake).

For Archive Binary Distrubtion of CMake:

You can also install CMake from binary distrubtion its extention is tar.gz. You just need to download it to your local disk, and then extract all file to a specified direcotry.

#1 Download archive binary file of CMake with the following command:

$ wget https://github.com/Kitware/CMake/releases/download/v3.13.4/cmake-3.13.4-Linux-x86_64.tar.gz

Outputs:

devops@devops-osetc:/tmp/cmaked$ wget https://github.com/Kitware/CMake/releases/download/v3.13.4/cmake-3.13.4-Linux-x86_64.tar.gz
--2019-02-28 06:46:56-- https://github.com/Kitware/CMake/releases/download/v3.13.4/cmake-3.13.4-Linux-x86_64.tar.gz
Resolving www-proxy.us.osetc.com (www-proxy.us.osetc.com)... 148.87.19.20
Connecting to www-proxy.us.osetc.com (www-proxy.us.osetc.com)|148.87.19.20|:80... connected.
Proxy request sent, awaiting response... 302 Found
Location: https://github-production-release-asset-2e65be.s3.amazonaws.com/537699/8cd62280-2625-11e9-89fe-f324766c574b?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20190314%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190314T090106Z&X-Amz-Expires=300&X-Amz-Signature=f6fb6d98e76474fbe058da8619ff43b09e4822f3d753809d2e091182e2a26bd2&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Dcmake-3.13.4-Linux-x86_64.tar.gz&response-content-type=application%2Foctet-stream [following]
--2019-02-28 06:46:57-- https://github-production-release-asset-2e65be.s3.amazonaws.com/537699/8cd62280-2625-11e9-89fe-f324766c574b?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20190314%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190314T090106Z&X-Amz-Expires=300&X-Amz-Signature=f6fb6d98e76474fbe058da8619ff43b09e4822f3d753809d2e091182e2a26bd2&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Dcmake-3.13.4-Linux-x86_64.tar.gz&response-content-type=application%2Foctet-stream
Connecting to www-proxy.us.osetc.com (www-proxy.us.osetc.com)|148.87.19.20|:80... connected.
Proxy request sent, awaiting response... 200 OK
Length: 38405896 (37M) [application/octet-stream]
Saving to: ‘cmake-3.13.4-Linux-x86_64.tar.gz’

cmake-3.13.4-Linux-x86_64.tar.gz 100%[==========================================================================>] 36.63M 413KB/s in 91s

2019-02-28 06:48:29 (414 KB/s) - ‘cmake-3.13.4-Linux-x86_64.tar.gz’ saved [38405896/38405896]

#2 Extract all files from the above downloaded CMake archive binary file, type:

$ tar -xvf cmake-3.13.4-Linux-x86_64.tar.gz

#3 changing the current directory to cmake-3.13.4-Linux-x86_64

$ cd cmake-3.13.4-Linux-x86_64

#4 CMake executable will be in ./cmake-3.13.4-Linux-x86_64/bin/ directory.

$ ls

Outputs:

devops@devops-osetc:/tmp/cmaked/cmake-3.13.4-Linux-x86_64/bin$ ls
ccmake cmake cmake-gui cpack ctest

#5 executing cmake script to check the current CMake version, type:

$ ./cmake --version

Outputs:

devops@devops-osetc:/tmp/cmaked/cmake-3.13.4-Linux-x86_64/bin$ ./cmake --version
cmake version 3.13.4

CMake suite maintained and supported by Kitware (kitware.com/cmake).

Installing CMake from Source Code


You can also compile the latest source code of CMake to install it. At this time, the latest stable version of CMake is 3.13.4. So you need to donwload the archive source code from the offical CMake web page, then compiling it. Just do the following steps:

#1 before downloading souce code, you need to unisntall the defualt older version of CMake by the default Ubuntu Package manager. Type:

$ sudo apt purge cmake

#2 go to the official download page to get the latest version of CMake with the following wget command:

$ wget https://github.com/Kitware/CMake/releases/download/v3.13.4/cmake-3.13.4.tar.gz

#3 extract all files from downloaded archive file, type:

$ tar -zxvf cmake-3.13.4.tar.gz

#4 changing the current dirctory to cmake-3.13.4, type:

$ cd cmake-3.13.4

#5 compiling and install cmake with the following commands:

$ ./bootstrap
$ make
$ sudo make install

Outputs:

devops@devops-osetc:~/cmake-3.13.4$ ./bootstrap
---------------------------------------------
CMake 3.13.4, Copyright 2000-2018 Kitware, Inc. and Contributors
Found GNU toolchain
C compiler on this system is: gcc
C++ compiler on this system is: g++
Makefile processor on this system is: make
g++ has setenv
g++ has unsetenv
g++ does not have environ in stdlib.h
g++ has stl wstring
g++ has <ext/stdio_filebuf.h>
---------------------------------------------
g++ -I/home/devops/cmake-3.13.4/Bootstrap.cmk -I/home/devops/cmake-3.13.4/Source -I/home/devops/cmake-3.13.4/Source/LexerParser -I/home/devops/cmake-3.13.4/Utilities -c /home/devops/cmake-3.13.4/Source/cmAddCustomCommandCommand.cxx -o cmAddCustomCommandCommand.o

-- Looking for a Fortran compiler - NOTFOUND
qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or directory
qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or directory
-- Performing Test run_pic_test
-- Performing Test run_pic_test - Success
-- Performing Test run_inlines_hidden_test
-- Performing Test run_inlines_hidden_test - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /home/devops/cmake-3.13.4
---------------------------------------------
CMake has bootstrapped. Now run make.

devops@devops-osetc:~/cmake-3.13.4$ make
Scanning dependencies of target cmsys
[ 0%] Building C object Source/kwsys/CMakeFiles/cmsys.dir/ProcessUNIX.c.o
[ 0%] Building C object Source/kwsys/CMakeFiles/cmsys.dir/Base64.c.o
[ 1%] Building C object Source/kwsys/CMakeFiles/cmsys.dir/EncodingC.c.o
......
Scanning dependencies of target pseudo_cpplint
[100%] Building C object Tests/RunCMake/CMakeFiles/pseudo_cpplint.dir/pseudo_cpplint.c.o
[100%] Linking C executable pseudo_cpplint
[100%] Built target pseudo_cpplint
Scanning dependencies of target foo
[100%] Building CXX object Tests/FindPackageModeMakefileTest/CMakeFiles/foo.dir/foo.cpp.o
[100%] Linking CXX static library libfoo.a
[100%] Built target foo

devops@devops-osetc:~/cmake-3.13.4$ sudo make install

-- Installing: /usr/local/share/cmake-3.13/editors/vim/syntax
-- Installing: /usr/local/share/cmake-3.13/editors/vim/syntax/cmake.vim
-- Installing: /usr/local/share/cmake-3.13/editors/emacs/cmake-mode.el
-- Installing: /usr/local/share/aclocal/cmake.m4
-- Installing: /usr/local/share/cmake-3.13/completions/cmake
-- Installing: /usr/local/share/cmake-3.13/completions/cpack
-- Installing: /usr/local/share/cmake-3.13/completions/ctest

#6 checking CMake version to verify if it is installed successfully, type:

$ cmake --version

Outputs:

devops@devops-osetc:~/cmake-3.13.4$ cmake --version
cmake version 3.13.4

CMake suite maintained and supported by Kitware (kitware.com/cmake).

Installing CMake GUI


If you want to install CMake GUI on your Ubuntu system, you just need to use apt install command to install it, type:

$ sudo apt install cmake-qt-gui

Outputs:

devops@devops-osetc:~$ sudo apt install cmake-qt-gui
[sudo] password for devops:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
augeas-lenses cpu-checker cryptsetup cryptsetup-bin db-util db5.3-util dmeventd extlinux hfsplus icoutils ipxe-qemu ipxe-qemu-256k-compat-efi-roms
ldmtool libafflib0v5 libaugeas0 libbfio1 libcacard0 libconfig9 libdate-manip-perl libdevmapper-event1.02.1 libewf2 libfdt1 libhfsp0 libhivex0
libintl-perl libintl-xs-perl libiscsi7 libldm-1.0-0 liblvm2app2.2 liblvm2cmd2.02 librados2 librbd1 libsdl1.2debian libspice-server1 libssl-doc
libstring-shellquote-perl libsys-virt-perl libtsk13 libusbredirparser1 libvirt0 libwin-hivex-perl libxen-4.9 libxenstore3.0 lsscsi lvm2 msr-tools
osinfo-db qemu-block-extra qemu-system-common qemu-system-x86 qemu-utils scrub seabios sgabios sleuthkit supermin zerofree
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
cmake
Suggested packages:
cmake-doc ninja-build
The following NEW packages will be installed:
cmake cmake-qt-gui
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,635 kB/4,773 kB of archives.
After this operation, 22.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y

Processing triggers for shared-mime-info (1.9-2) ...
Processing triggers for gnome-menus (3.13.3-11ubuntu1.1) ...
Setting up cmake (3.10.2-1ubuntu2) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Setting up cmake-qt-gui (3.10.2-1ubuntu2) ...

Then you can use the following commands to check if CMake-gui package is installed normally:

$ which cmake-gui

Or

$ cmake-gui --version

You can run the cmake-gui command in Ubuntu terminal to launch the cmake gui, type:

$ cmake-gui

ubuntu install cmake2

Conclusion


You should know that how to install CMake tool on Ubuntu 16.04 or 18.04 from this guide, and you also know how to install CMake with the different methods on Ubuntu Linux server(default ubuntu repo, PPA, Source code). If you want to see more information about CMake, you can go the official web site of CMake directly.

You might also like:

Sidebar



back to top