2

I wanted to update my cmake version. So I had first uninstalled it and then tried to install as given in this post by teocci.

However, it was giving some errors on entering make and now I want to uninstall it and install the previous version of cmake. I tried sudo apt-get purge cmake. But it still remains in the system on entering cmake --version.

What should I do?

  • Can you post the log message you get from running the sudo apt-get purge cmake command. – AmeyaVS Aug 3 '17 at 16:47
  • Thanks for the reply. It shows 0 upgraded, 0 newly installed, 0 to remove and 314 not upgraded. It also says Use 'apt-get autoremove' to remove some files listed above.. However I'm reluctant to use autoremove as it removed a few important files in the past. – Surabhi Verma Aug 3 '17 at 16:57
  • what version of Ubuntu you are using and what is the version of cmake reported by cmake --version?, and also what is the output of the command which cmake? – AmeyaVS Aug 3 '17 at 17:03
  • 1
    @SurabhiVerma Please don't attempt to manually remove files yet. I believe CMake supports automatic uninstallation, and I expect to post an answer soon. I think CMake supports sudo make uninstall run from the same place you ran sudo make install. (Programs you create yourself and use CMake to generate build scripts for don't automatically support this, but I believe CMake does.) I'm compiling CMake now to test it, and I'll answer if it works or comment if it doesn't. Even if I'm mistaken that this works, I still recommend you wait a while for other answers before manually deleting files. – Eliah Kagan Aug 3 '17 at 17:38
  • 1
    @SurabhiVerma You can get it back by repeating the steps you used to install it and installing again. So long as you use the same version (i.e., start from the same .tar.gz file) and pass exactly the same options (if you used any) to ./bootstrap, then when you install it, it will install the same files it had already installed (harmlessly overwriting them) and then you can run sudo make uninstall. But you may want to wait to try this until I've finished checking that sudo make uninstall does actually work to uninstall CMake. (I'll make sure to mention this situation in my answer.) – Eliah Kagan Aug 3 '17 at 17:50
6

TL;DR: Run sudo make uninstall in the directory where you ran sudo make install before.

You followed this method of installing a different version of CMake. This is to say that you uninstalled the version provided by Ubuntu's package manager and manually downloaded, compiled, and installed it yourself from source code.

Assuming you were able to follow those instructions successfully, the version of CMake provided by Ubuntu's package manager (via the cmake package) is already uninstalled. Because the version that you have installed now is not provided by Ubuntu's package manager, but instead the version you compiled and installed yourself, running sudo apt-get purge cmake again does not remove it.

Since you installed cmake by compiling it and then running sudo make install, the solution is for you to:

  1. Use cd to go back to the directory where you ran that command.
  2. Run sudo make uninstall.

Not all software that can be installed by running make install has a corresponding uninstall target letting you run make uninstall to remove it. But CMake does support this.1

If you have deleted the folder in which you ran sudo make install, or otherwise changed it, then your best bet is to rebuild and reinstall it (be sure to use exactly the same version) to get back the ability to run sudo make uninstall. That is, you would follow the same installation steps, starting from the same .tar.gz file and passing all the same options you used (if any) to ./bootstrap. If you just ran ./bootstrap with no arguments after it, do that again. After running sudo make install again, which would (harmlessly) overwrite the files that were already installed with copies of themselves, you would then be able to use sudo make uninstall.

Another possible approach, which I strongly discourage you from doing, would be to try to figure out exactly what files and directories were created in the installation, and to try to remove just those files and directories but no others. If you did not pass the --prefix to ./bootstrap when you compiled CMake then it installed files in /usr/local, but it is not the only program that uses that directory. It would have installed files in the various subdirectories of /usr/local, such as bin and lib (and others), so aside from the situation where you know nothing else was installed into /usr/local, this option requires a lot of work.


1 It's easy to become confused about whether or not you can uninstall CMake by running sudo make uninstall because, by default, when you use CMake to create build scripts for your own software, no uninstall target is generated unless you explicitly ask for one. However, CMake itself is designed to be easily uninstalled, and its source code does define those uninstall targets for itself. In the Makefile generated from running ./bootstrap you can see:

#=============================================================================
# Target rules for targets named uninstall

# Build rule for target.
uninstall: cmake_check_build_system
    $(MAKE) -f CMakeFiles/Makefile2 uninstall
.PHONY : uninstall

# fast build rule for target.
uninstall/fast:
    $(MAKE) -f CMakeFiles/uninstall.dir/build.make CMakeFiles/uninstall.dir/build
.PHONY : uninstall/fast

You can also search for uninstall support in its CMakeLists.txt file.

To be sure, I tested this with CMake 3.9.0, and it does work. The uninstall target is generated and running sudo make uninstall works to uninstall CMake.

  • Thank you so much. It takes quite some time to install.. So meanwhile I would like to ask that if I now want a newer version of cmake(like the version provided by Ubuntu's package manager and not like the one I had manually installed) what should I do? – Surabhi Verma Aug 3 '17 at 18:04
  • @SurabhiVerma I'm glad this worked! As for how to upgrade: that depends: what went wrong with the CMake you installed? What errors happened? What version did you install? Why was the version in Ubuntu insufficient? Do you just want to try out a newer version? (Of course that's OK, but if there's a more specific reason, it may be relevant.) Are you trying to build something that needs a newer version of CMake? If so, what? You should post a separate question for this, but if you explain the situation a bit, maybe I can suggest other things to include in it that would make it easier to answer. – Eliah Kagan Aug 3 '17 at 18:17
  • I want a newer version for new cmake functions(for pybind11) for which I needed version 3 or above. So I uninstalled cmake(V 2.8.2) and installed a new version by the procedure I mentioned. But then on running make I got the following error.. make: /usr/bin/cmake: Command not found.. So I deleted that folder where I had installed the new version and ran sudo apt-get install cmake to install the old version again and then it threw this error: CMake Error: Error executing cmake::LoadCache(). Aborting.. So I thought maybe I didn't install properly.. So i again deleted it. – Surabhi Verma Aug 3 '17 at 18:27
  • @SurabhiVerma Apparently pybind11 was unable to find the cmake command you installed yourself because it expected it to be at /usr/bin/cmake, which seems like a bug, but one that could be worked around. CMake 2.8.2 is quite old; Ubuntu 14.04 has CMake 2.8.12. What Ubuntu release are you running? What's the output of lsb_release -rd and apt-cache policy cmake | grep -oP 'Candidate: \K.+'? How did you download pybind11's source code, and what version is it (or did you check out the head from git)? – Eliah Kagan Aug 3 '17 at 18:56
  • 1
    I installed cmake via this and make works now.. Thanks for the help :) – Surabhi Verma Aug 4 '17 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.