In certain situations, installing the latest version of CMake from a source tarball may be necessary. The following scenarios illustrate the benefits of doing so:
- Outdated Distribution Version: Many Linux distributions come with a pre-installed version of CMake, which may be outdated. Older versions of CMake can also be found in Linux distribution repositories. If a project requires a newer version of CMake, installing from a source tarball provides access to the latest features and bug fixes.
- New CMake Features: The latest version of CMake may introduce new features, such as improved support for certain cross-compilers (e.g., Raspberry Pi Pico SDK), languages, or build systems. Installing CMake from a source tarball ensures compatibility with projects that rely on these new features. The CMake version needed for a given project could be higher than what is available in the distribution repositories for the build setup. In those situations, the most recent CMake can be useful.
- Essential Bug Fixes: Sometimes, a specific bug in an earlier version of CMake can cause issues with a project's build process. Installing the latest version from a source tarball provides the necessary bug fixes, ensuring a smooth build experience.
- Custom or Non-Standard Build Configurations: Certain projects may require custom or non-standard build configurations, which can be better supported by the latest version of CMake. Installing from a source tarball allows for more flexibility in configuring the build process.
- Cross-Compilation or Embedded Systems Development: When working with cross-compilation or embedded systems development, the version of CMake provided by the distribution may not be suitable. Installing CMake from a source tarball provides the necessary customisation options for these specialised use cases.
- Package Manager Limitations: In some cases, the package manager (e.g., apt, yum, or Homebrew) may not provide the latest version of CMake or may have limitations on the versions available. Installing from a source tarball bypasses these limitations, allowing for the installation of the desired version.
- Development or Testing Environments: Developers or testers may need to test their projects with different versions of CMake, including the latest one. Installing CMake from a source tarball provides an easy way to manage multiple versions and test environments.
The following steps outline the process of building and installing CMake from a source tarball on Linux, tested on Debian Bookworm.
To verify the currently installed version of CMake, run the following command:
cmake --version
The output will display the version number, similar to:
cmake version 3.25.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
Download the latest CMake source from the Kitware CMake GitHub repository. Select the "Source code" option in (tar.gz)
format, and download the CMake-{version number}.tar.gz
file.
Navigate to the ~/Downloads
directory (for example) and extract the source tarball:
cd ~/Downloads/
tar -zxvf 'CMake-{version number}.tar.gz'
Enter the extracted source directory and bootstrap the build process:
cd CMake-{version number}/
./bootstrap
Use gmake
to run the build process:
gmake
If the build process completes successfully, install the built binary using sudo
privileges:
sudo gmake install
To confirm the installation, check the CMake version number:
cmake --version
The output should display the newly installed version, similar to:
cmake version 3.31.3
CMake suite maintained and supported by Kitware (kitware.com/cmake).
By following these steps, users can ensure they have the latest version of CMake installed, providing access to the latest features, bug fixes, and customisation options for their projects.