16

I'm trying to build a github project using cmake and I've been having a lot of trouble. I'm creating a build directory and calling cmake like so:

cd github_project_directory
mkdir build
cd build
cmake ..

This is the error I'm getting:

CMake Error: Could not find CMAKE_ROOT !!!
CMake has most likely not been installed correctly.
Modules directory not found in
/usr/bin
CMake Error: Error executing cmake::LoadCache(). Aborting.

I think there is a problem with how cmake is installed but I can't seem to figure it out. I've tried uninstalling and reinstalling but...I think it might have created even more trouble.

I'm on Ubuntu 14.04. Happy to provide more information as required.

Thank you!

ellen
  • 277

5 Answers5

9

I was getting the same error for anything cmake, including cmake --version, and the "reinstall cmake and cmake-data, then restart your shell" answers didn't work, so I tried manually setting CMAKE_ROOT to the path from dpkg -L cmake-data that contains the Modules directory.

export CMAKE_ROOT=/usr/share/cmake-3.5

That got cmake --version working, which revealed that I was somehow dealing with a cmake that reported itself as cmake 2.x, but a cmake-data package which created a cmake-3.5 folder for its resources.

It turned out that one of my PPAs was offering cmake 3.5 at the same package names that 14.04 uses for cmake 2.8 and, because of a dependency conflict, the cmake-data package had upgraded to 3.5, but the cmake package was getting held back at 2.8.

The following lines got things working for me:

sudo apt-get remove cmake cmake-data
sudo apt-get install cmake3 cmake3-data
ssokolow
  • 2,423
6

I had to re-install my cmake to correct this same error.

sudo apt-get remove cmake cmake-data
sudo -E add-apt-repository -y ppa:george-edison55/cmake-3.x
sudo -E apt-get update
sudo apt-get install cmake

Then be sure to re-source your rc.

. ~/.bashrc
D M Lowe
  • 169
3

Runing . ~/.bashrc also solved the problem for me. My total procedure was -

sudo apt remove cmake // as it was a old version and i needed new one
pip install cmake --upgrade
sudo apt autoremove
. ~/.bashrc
2

You could use the version from pip

pip install cmake

➜ ~ cmake --version
cmake version 3.18.2
Eugene K
  • 123
0

If you run into this issue after you install a new/updated/different cmake version, please try running hash -r.

Credit to https://stackoverflow.com/questions/18615451/cmake-missing-modules-directory