[4 Solutions] - to fix "cmake: command not found" error in macOS, Linux and Windows

This post helps you to fix the "cmake: command not found" error encountered during the build process of your software. There are two major reasons for getting cmake command errors, either cmake is not installed or Path is not correctly set up. It doesn't matter, which operating system you have. Following this post step by step will get this issue resolved for sure.

Below mentioned are the types of errors that occur while working with the "cmake" command -

  1. cmake: command not found
  2. cmake command not found macOS
  3. autogen.sh cmake command not found
  4. /bin/sh cmake command not found
  5. 'cmake' is not recognized as an internal or external command, operable program or batch file
  6. command 'cmake' not found
  7. bash: /snap/bin/cmake: No such file or directory

Why am I getting the "cmake: command not found" error?

Following are the reason for getting the cmake command not found issue -

  • cmake is not installed in your operating system
  • cmake is installed but PATH or environmental variable is not setup correctly

How to fix CMake: command not found error in macOS

Let's assume you are trying to build software which is trying to run "build && cmake" commands and you are getting cmake errors. It means you don't have the CMake package installed in your macOS.

To solve this CMake issue, we will follow 3 steps approach -

  • Check if CMake is installed or not
  • If it's not installed, install the cmake using the right way.
  • If CMake is installed but not working, then look for the PATH variable.

The above-mentioned approach is applicable to all operating systems whether it's Windows, Debian, RedHat or macOS.

How to check "CMake" package is installed or not

The best way is to run the CMake command -

  • Open a terminal in macOS
  • Run cmake command see the output
$ cmake

If it shows the cmake help, then cmake is installed in your system and your life is sorted, else you need to install cmake using the following command.

$ brew install cmake
  • Alternatively, you can also go to the cmake download page and download the precompiled binaries as disk image ".dmg" or ".tar.gz" (tarball) binary as per your macOS version.
Download cmake for macOS
  • Copy CMake.app into /Applications (or a custom location) and then double click to run it. Then follow the “How to Install For Command Line Use” menu item

Once you install the cmake it will automatically be available in the PATH. but in case you don't have that automatically and get the cmake: command not found error, then you need to set up the cmake PATH manually using the following commands -

How to setup PATH for cmake in macOS

  • Open .bash_profile or .bashrc in your home directory using vim or nano editor.
  • Add the following line to the end of the file and save the file.

export PATH="/Applications/CMake.app/Contents/bin":"$PATH"

  • If you want to create symlinks to '/usr/local/bin', run the following command from the terminal
$ sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install

How to fix command 'cmake' not found error in Linux

If you use Ubuntu or any other Debian-based Linux and get "cmake: command not found errors", then follow these series of commands -

Step-1 check for existing cmake installation

cmake: command not found error

As shown in the above image, cmake is not installed in my Linux system.

Step2- Install cmake, if not installed already

How to install cmake in Linux - 4 Methods

There are 4 ways to install cmake in your Debian Linux system like Ubuntu, LinuxMint, Kubuntu, Kali Linux etc.

  • 1. Using the apt command

Run the following commands -

$ sudo apt update
$ sudo apt install cmake
Install cmake in Ubuntu using apt
  • 2. Using the snap command as the apt command is going to obsolete soon
$ sudo snap install cmake --classic
Install cmake in Debian based os using snap
  • By using pre-compiled binaries available on the make download page.
download precompiled binaries for cmake to install in Linux
  • 3. Download the cmake-3.24.2-linux-x86_64.sh file and execute it.
$ bash cmake-3.24.2-linux-x86_64.sh
run cmake.sh file to install it in Linux
  • Accept license by typing "y" and either accept the default location to install or provide your custom directory.
Accept license

** Note - whatever the directory location you will provide in the above step, the same path you need to include in $PATH manually if the cmake command gives you an error.

For example, in my case, I will add the following line to the last of .bashrc or .bash_profile file in the user's home directory

$ export PATH=$PATH:/home/dev/Downloads/cmake-3.24.2-linux-x86_64/bin
  • Check the command "cmake" is running successfully

$ cmake

cmake: command not found error in linux fixed

How to fix 'cmake' is not recognized as an internal or external command, operable program or batch file error in Windows

In the case of the Windows operating system, if you get cmake command errors, then follow the below-mentioned process to fix it.

  • Download cmake binaries from the cmake website
Download cmake command for Windows
  • Double-click on the installer and click "next" on the welcome page
  • Accept the license and hit next in the wizard
Accept EULA
  • Important step - Select the option to add the CMake directory to the system PATH.

You will get 3 options -

  1. Do not add CMake to the system PATH - If you have selected this option, then you need to add the CMake path manually in the system after installation. That is one of the reasons when you have cmake installed and still, you get "'cmake' is not recognized as an internal or external command" error. So don't select this option.
  2. Add CMake to the system PATH for all users - If you log in with different users to your system, then you can select this option. It will set up the cmake PATH variable for all users, who is present on the system.
  3. Add CMake to the system PATH for the current user - If you are the only user, then this is the recommended option.

You can select either option 2 or 3 based on your requirement, both will set up the PATH variable in your environment and will fix the cmake command errors.

Setup PATH variable to fix cmake' is not recognized as an internal or external command error
  • Select custom or leave it to default for the cmake installation directory.
how to install cmake in Windows
  • Then Click Install and accept select "Yes" in case of user control dialogue box permission
  • Click Finish, once the cmake installation is done
finish cmake installation wizard
  • Open the command prompt and run the cmake command to validate.
c:\> cmake
run cmake command

How to install CMake in Docker

Add this line to install CMake in the Docker file -

#!/bin/bash
wget -qO- "https://github.com/Kitware/CMake/releases/download/v3.24.2/cmake-3.24.2-linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local

Change the version with your required version, I have shown an example of v3.24.2 latest available while writing this article. If you get the error wget command not found, then add appt update && apt install wget in your file.

End note

The fundamental approach is the same to troubleshoot the CMake command not found error in all operating systems -

  1. Check for cmake installation
  2. Install cmake as shown in this post for your operating systems
  3. setup PATH or Environment variable, if required
  4. Run cmake and build apps

Leave your feedback or comments, if you face any other issues in the cmake command.

Other helpful articles

Leave a Comment

Your email address will not be published.