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 –
- cmake: command not found
- cmake command not found macOS
- autogen.sh cmake command not found
- /bin/sh cmake command not found
- ‘cmake’ is not recognized as an internal or external command, operable program or batch file
- command ‘cmake’ not found
- 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
cmakecommand see the output
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.
- 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
.bashrcin your home directory using vim or nano editor.
- Add the following line to the end of the file and save the file.
- 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
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
- 2. Using the snap command as the apt command is going to obsolete soon
$ sudo snap install cmake --classic
- By using pre-compiled binaries available on the make download page.
- 3. Download the cmake-3.24.2-linux-x86_64.sh file and execute it.
$ bash cmake-3.24.2-linux-x86_64.sh
- Accept license by typing “y” and either accept the default location to install or provide your custom directory.
** 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
.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
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
- Double-click on the installer and click “
next” on the welcome page
- Accept the license and hit
nextin the wizard
- Important step – Select the option to add the CMake directory to the system PATH.
You will get 3 options –
- 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.
- 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.
- 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.
- Select custom or leave it to default for the cmake installation directory.
- Then Click
Installand accept select “Yes” in case of user control dialogue box permission
- Click Finish, once the cmake installation is done
- Open the command prompt and run the
cmakecommand to validate.
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.
The fundamental approach is the same to troubleshoot the CMake command not found error in all operating systems –
- Check for cmake installation
- Install cmake as shown in this post for your operating systems
- setup PATH or Environment variable, if required
- Run cmake and build apps
Leave your feedback or comments, if you face any other issues in the cmake command.