Some people prefer installing applications or APIs from Ubuntu package so that they can keep tracking the installations of applications in apt list or Synaptic package management. However, Ubuntu packages are sometimes outdated. Some people upload the latest version of deb packages online, but these packages may damage apt packages. The broken Ubuntu package rarely happened to me after Ubuntu 18.04 in these days, but I had such problems in the past. Recovering Ubuntu packages is very difficult. So, I prefer installing CMake or some programming APIs by building their sources codes so that I can get the latest version. However, building the source code to install an application is more difficult than just running apt command, and it usually takes longer period of time than apt command. Yes, it is difficult, but build to install application is not too difficult if you have done it once or twice. I would like to instruct you how to install CMake from source code here. Once, you are familiar with build to install. You can apply similar steps for other applications too.
What’s CMake about?
CMake is open-source cross-platform building tool, which allow you to compile a program in different platforms. You can compile your C program on Linux, Mac, or Windows by cmake.
Requirements: wget, git, gcc/g++compiler, tar, openssl, libssl-dev, libncurses5-dev, gfortran
Installation Steps:
- Git Clone or Download CMake source code:
NOTE: I PREFER GIT CLONE THE CMAKE SOURCCE BECAUSE THE CMAKE SOURCE CODE FROM THEIR HOME PAGE DOES NOT INCLUDE CCMAKE.
git command: git clone https://github.com/Kitware/CMake.git
CMake Github: https://github.com/Kitware/CMake
Or
Download source from CMake Home page: wget https://github.com/Kitware/CMake/releases/download/v3.24.0-rc5/cmake-3.24.0-rc5.tar.gz
NOTE: PLEASE SET THE LATEST CMAKE SOURCE CODE URLS.
CMake source code has been downloaded.
Unzip the source code: tar -xvf cmake-3.24.0-rc5.tar.gz
CMake Download Page: https://cmake.org/download/
3. Change directory to cmake source directory: cd CMake
4. Before installing cmake, you should make installation directory. I prefer installing cmake in /opt/cmake. This is because I want to just make sure where I install cmake and also avoid the default location /usr/local. It may overwrite something. Create directory /opt/cmake: sudo mkdir -p /opt/cmake
To find the default installation location: ./bootstrap –help
5. Run configuration script bootstrap: ./bootstrap –prefix=/opt/cmake
Makre sure you get configuration message without error. You see “Now run make” if boostrap successfully executed.
6. Build: make all or make -j4 all (4 is number of CPU cores)
Make sure that you do not receive any error.
7. Install CMake to /opt/cmake: sudo make install
8. Check cmake binaries in /opt/cmake/bin
NOTE: PLEASE MAKE SURE THAT THERE IS CCMAKE. YOU NEED CCMAKE MOST OF THE TIME WHEN YOU INSTALL PROGRAMMING API.
9. Make a symbolic link of cmake command: sudo ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake
10. Make symbolic link of ccmke: sudo ln -s /opt/cmake/bin/ccmake /usr/local/bin/ccmake
11. Run cmake command: cmake –verison
Run ccmake commnad as well.
NOTE: MAKE SURE YOU HAVE CORRECT CMAKE VERSION.
12. Done
Troubleshoot:
You may receive below error if have not install libssl-dev.
Solution: sudo apt install libssl-dev
Reference URLs:
CMake Home Page: https://cmake.org/
CMake Download Page: https://cmake.org/download/
CMake Github: GitHub – Kitware/CMake: Mirror of CMake upstream repository