CentOSRHEL Based

How To Install CMake on CentOS Stream 10

Install CMake on CentOS Stream 10

CMake stands as a pivotal tool in modern software development, streamlining the build process across diverse platforms. It acts as a build system generator, creating standardized build files that can be used with native build environments like Make, Ninja, and IDEs such as Visual Studio or Eclipse. This article will guide you through the installation of CMake on CentOS Stream 10, ensuring you can effectively manage your software projects. This guide includes multiple installation methods to suit different needs and preferences. Let’s explore the simple steps to get CMake up and running, enhancing your development workflow.

Prerequisites

Before diving into the installation process, it’s essential to ensure that your system meets certain prerequisites. This preparation avoids potential conflicts and ensures a smooth installation experience. Here’s what you need to get started:

System Requirements

  • CentOS Stream 10 Fresh Installation: Begin with a clean CentOS Stream 10 installation to minimize potential conflicts with existing software.
  • Root or Sudo Privileges: You’ll need administrative rights to install software. Ensure you have either root access or a user account with sudo privileges.
  • Minimum System Specifications: While CMake itself doesn’t demand high resources, ensure your system meets the basic requirements for development work, including sufficient RAM and storage.
  • Terminal Access: All installation steps will be performed via the command line, so ensure you have access to a terminal.

Required Base Packages

CentOS Stream 10 requires certain base packages to be installed to support the compilation process. These packages include development tools, compilers, and other essential dependencies.

  • Development Tools:
    • Install the “Development Tools” group, which provides essential tools like GCC, Make, and other utilities necessary for compiling software.
  • Compiler Requirements:
    • Ensure you have a C++ compiler installed, such as GCC, which is essential for compiling C++ projects using CMake.
  • Basic Dependencies:
    • Install any additional dependencies required by CMake, such as zlib, bzip2, and openssl.

Method 1: Installing CMake via DNF

The simplest way to install CMake on CentOS Stream 10 is by using the DNF package manager. This method ensures that you get a stable version of CMake along with automatic updates and dependency management.

System Preparation

Before installing CMake, it’s crucial to update your system to ensure you have the latest packages and dependencies.

  • System Update Commands:
    • Open your terminal and run the following command to update your system:
      sudo dnf update -y

      This command updates all installed packages to their latest versions.

  • Repository Configuration:
    • CentOS Stream 10 typically has the necessary repositories configured by default. However, ensure that the “BaseOS” and “AppStream” repositories are enabled.
  • Installation of Dependencies:
    • Install any missing dependencies that CMake might require. Usually, DNF handles these dependencies automatically, but it’s good to ensure everything is in place.

Standard Installation Process

With your system prepared, you can proceed with the CMake installation using DNF.

  • DNF Installation Commands:
    • Run the following command to install CMake:
      sudo dnf install cmake -y

      This command downloads and installs CMake from the configured repositories.

  • Version Verification:
    • After the installation, verify that CMake is correctly installed by checking its version:
      cmake --version

      This command displays the installed CMake version, confirming the successful installation.

  • Basic Configuration Steps:
    • CMake doesn’t require extensive configuration after installation. However, ensure that the CMake executable is in your system’s PATH to use it from any directory.

Method 2: Installing CMake from Source

Installing CMake from source provides the flexibility to use the latest CMake version or customize the build process. This method involves downloading the source code, compiling it, and then installing CMake on your system.

Downloading Source Code

The first step is to download the CMake source code from the official CMake website or a reliable mirror.

  • Obtaining Latest Stable Release:
    • Visit the CMake downloads page and find the latest stable release source code (usually a .tar.gz or .tar.bz2 file).
    • Download the source code using wget or curl:
      wget https://cmake.org/files/v3.x/cmake-3.x.x.tar.gz

      Replace 3.x.x with the actual version number.

  • Verification of Downloaded Files:
    • Verify the integrity of the downloaded file using checksums (SHA256 or MD5) provided on the CMake website. This ensures that the file is not corrupted during the download.
  • Extraction Process:
    • Extract the downloaded source code using the tar command:
      tar -zxvf cmake-3.x.x.tar.gz

      This command extracts the source code into a new directory named cmake-3.x.x.

Compilation Process

After extracting the source code, navigate into the extracted directory and begin the compilation process.

  • Configuration Steps:
    • Change into the CMake source directory:
      cd cmake-3.x.x

      Create a build directory:

      mkdir build
      cd build

      Configure the build using CMake:

      ../configure

      This command prepares the build environment.

  • Build Process:
    • Compile the source code using the make command:
      make

      This process compiles the CMake source code. It may take some time depending on your system’s resources.

  • Installation Commands:
    • Install CMake using the make install command with sudo privileges:
      sudo make install

      This command installs CMake to /usr/local/bin by default.

Post-Installation Setup

After installing CMake, configure the environment variables to ensure that CMake can be accessed from any terminal.

  • Environment Variable Configuration:
    • Add CMake to your system’s PATH by editing your shell’s configuration file (e.g., .bashrc or .zshrc).
  • Path Settings:
    • Open your .bashrc file using a text editor:
      nano ~/.bashrc

      Add the following line to the end of the file:

      export PATH="/usr/local/bin:$PATH"

      Save the file and exit.

  • Version Verification:
    • Update your current shell session by running:
      source ~/.bashrc

      Verify that CMake is correctly installed by checking its version:

      cmake --version

      This command displays the installed CMake version, confirming the successful installation.

Method 3: Binary Distribution Installation

Installing CMake using pre-compiled binary distributions is another convenient way to get CMake up and running. This method involves downloading a pre-built binary package and extracting it to a directory in your system.

Download and Preparation

First, you need to download the appropriate binary distribution for CentOS Stream 10 from the CMake website.

  • Obtaining Pre-compiled Binaries:
    • Visit the CMake downloads page and look for the “Binary distributions” section.
    • Download the appropriate binary for Linux (usually a .tar.gz or .sh file).
  • Verification Steps:
    • Verify the integrity of the downloaded file using checksums (SHA256 or MD5) provided on the CMake website.
  • Directory Setup:
    • Create a directory where you want to install CMake. For example:
      sudo mkdir /opt/cmake

Installation Steps

After preparing the system and downloading the binary distribution, proceed with the installation.

  • Binary Deployment:
    • Extract the downloaded binary distribution to the created directory:
      sudo tar -zxvf cmake-3.x.x-Linux-x86_64.tar.gz -C /opt/cmake

      Replace cmake-3.x.x-Linux-x86_64.tar.gz with the actual filename of the downloaded binary.

  • System Integration:
    • Create a symbolic link to the CMake executable in /usr/local/bin to make it accessible system-wide:
      sudo ln -s /opt/cmake/cmake-3.x.x-Linux-x86_64/bin/cmake /usr/local/bin/cmake

      Replace cmake-3.x.x-Linux-x86_64 with the actual directory name.

  • Configuration Process:
    • Add CMake to your system’s PATH by editing your shell’s configuration file (e.g., .bashrc or .zshrc).
    • Open your .bashrc file using a text editor:
      nano ~/.bashrc

      Add the following line to the end of the file:

      export PATH="/opt/cmake/cmake-3.x.x-Linux-x86_64/bin:$PATH"

      Save the file and exit.

Testing the Installation

After installing CMake using any of the methods described above, it’s crucial to test the installation to ensure that it works correctly. This involves checking the CMake version and compiling a basic test project.

Verification Steps

  • Version Checking:
    • Open your terminal and run the following command:
      cmake --version

      This command displays the installed CMake version, confirming the successful installation.

  • Basic Test Project:
    • Create a simple C++ project with a CMakeLists.txt file to test the compilation process.
  • Compilation Test:
    • Create a directory for your test project:
      mkdir test_project
      cd test_project

      Create a simple C++ source file (e.g., main.cpp) with the following content:

      #include <iostream>
      
        int main() {
        std::cout << "Hello, CMake!" << std::endl;
        return 0;
        }

      Create a CMakeLists.txt file with the following content:

      cmake_minimum_required(VERSION 3.10)
      project(TestProject)
      
      add_executable(TestProject main.cpp)

      Create a build directory:

      mkdir build
      cd build

      Run CMake to generate the build files:

      cmake ..

      Compile the project:

      make

      Run the compiled executable:

      ./TestProject

      If everything is set up correctly, you should see “Hello, CMake!” printed to the console.

Troubleshooting Common Issues

While installing CMake, you may encounter some common issues. This section provides solutions to these problems, ensuring a smooth installation process.

  • Dependency Conflicts:
    • If you encounter dependency conflicts, ensure that all required dependencies are installed and that there are no conflicting versions. Use DNF to resolve dependency issues.
  • Compilation Errors:
    • If you encounter compilation errors while building from source, ensure that you have the necessary development tools and compilers installed. Check the error messages for specific details and install any missing libraries.
  • Path-Related Issues:
    • If CMake is not recognized after installation, ensure that the CMake executable is in your system’s PATH. Verify that you have correctly updated your shell’s configuration file (e.g., .bashrc or .zshrc).
  • Version Mismatch Solutions:
    • If you encounter issues due to version mismatches, ensure that you are using a compatible version of CMake with your project. Check the project’s documentation for specific version requirements.

Best Practices and Recommendations

To ensure a secure and efficient development environment, consider the following best practices and recommendations when using CMake.

  • Security Considerations:
    • Keep your CMake installation up to date to patch security vulnerabilities. Regularly check for updates and apply them promptly.
  • Performance Optimization:
    • Optimize your CMake build configurations for performance. Use appropriate compiler flags and build options to improve compilation times.
  • Update Management:
    • Regularly update CMake to benefit from the latest features and bug fixes. Use DNF or the appropriate method to update your installation.
  • Backup Procedures:
    • Back up your CMake configuration files and project files regularly to prevent data loss. Use version control systems like Git to manage your project files.

Congratulations! You have successfully installed CMake. Thanks for using this tutorial to install the CMake on CentOS Stream 10. For additional help or useful information, we recommend you check the official CMake website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button