14

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?

Eliah Kagan
  • 117,780
  • Can you post the log message you get from running the sudo apt-get purge cmake command. – AmeyaVS Aug 03 '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 03 '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 03 '17 at 17:03
  • Ubuntu 14.04, cmake version 3.9.0-rc5, /usr/local/bin/cmake – Surabhi Verma Aug 03 '17 at 17:05
  • It seems the cmake installation steps you followed from the linked answer is still installed the Ubuntu package manager is not able to track installation of applications installed by you. You need to manually delete the file's for this installation of cmake(be careful in removing files, do not by mistake delete any important system file!). – AmeyaVS Aug 03 '17 at 17:12
  • Oh, okay. How do I manually do it? – Surabhi Verma Aug 03 '17 at 17:13
  • 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 03 '17 at 17:38
  • Okay. I haven't started deleting it manually. But I have deleted that directory(the place from where I entered sudo make install) – Surabhi Verma Aug 03 '17 at 17:43
  • 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 03 '17 at 17:50
  • Ohkay.. I hope that works.. fingers crossed :/ – Surabhi Verma Aug 03 '17 at 17:54
  • @EliahKagan sudo make uninstall does work but it still keeps the directory structure which one would might want to remove since they are empty directories. Sorry my bad for previous comments. – AmeyaVS Aug 03 '17 at 17:56

1 Answers1

16

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.

Eliah Kagan
  • 117,780
  • 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 03 '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 03 '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 03 '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 03 '17 at 18:56
  • Ubuntu 14.04, 2.8.12.2-0ubuntu3(Oh my bad.. I thought I remember seeing it somewhere as version 2.8.2). I just cloned the git repository and added that to my package.. Oh and I also remember doing 'conda install -c conda-forge pybind11' – Surabhi Verma Aug 03 '17 at 19:05
  • @SurabhiVerma Okay, I recommend posting a new question about the problem installing pybind11. Please include the error messages and say how you downloaded the pybind11 source code (what was name of the downloaded file? or did you use git?), what version of cmake you downloaded and the full name of its .tar.gz file, the output of uname -m, and all info you've given in comments here, including release (14.04) and system-provided cmake version (2.8.12.2-0ubuntu3). If you comment here with a link to your new question, I'll look at it, though someone else might find and post a solution first. – Eliah Kagan Aug 03 '17 at 19:21
  • @SurabhiVerma Also, do you currently have Anaconda installed, and are you planning to use pybind11 with the Anaconda-provided python? How did you install Anaconda? Do you want to install pyblind11 in a Python virtual environment (virtualenv) or for the whole system? It's OK if you can't answer all this at the outset, but you should include what you can. If you don't remember the details of how you tried to install pybind11, I suggest doing it again so you can describe the steps you took and messages you saw. If you're using any online instructions, you can also link to them in your question. – Eliah Kagan Aug 03 '17 at 20:37
  • Yes, I have anaconda installed in my system. I followed this to install it. I still have the python version which came installed with ubuntu and I think anaconda takes care of the making a different virtual env. Whenever I type python --version.. the latest version of python which i downloaded shows. Well I just cloned the git repo.. I didn't know about the repo before so I had just installed pybind11 via conda. But, I have still included the git repo path in cmakelists rather than finding the lib in system. – Surabhi Verma Aug 04 '17 at 03:44
  • pybind11 installation was never a problem.. In fact I never got the above mentioned errors on running make until I needed a newer version of cmake and things got messed up and I don't have any version of cmake now.. So I'm wondering the best way of installing the newest version.. because on following the method given by teocci(as said in the question), cmake did not get installed in the default /usr/bin location – Surabhi Verma Aug 04 '17 at 03:46
  • @SurabhiVerma My guess is, when you installed pybind11 it saw /usr/bin/cmake and is still using it, and if you reinstall pybind11 it will see wherever cmake is now. But that is just a guess and there may be other more effective, easier, or otherwise better solutions. I still recommend you post a new question about this. conda is a good way to install Python tools and it is likely better than Git for installing pybind11. I had mentioned Git only [a] to find out what version of pybind11 you have (this is still relevant) and [b] because I thought you couldn't install it successfully. – Eliah Kagan Aug 04 '17 at 08:55
  • @SurabhiVerma Maybe there's a way to tell the installed pybind11 to use /usr/local/bin/cmake. Or a quick fix may be to symlink /usr/bin/cmake to it. This could work if pybind11 isn't relying on the version of CMake it thinks is installed or where CMake's other files are (I don't know enough about pybind11 to tell without checking). Or you could rebuild CMake with a prefix /usr/bin and use checkinstall (as sudo make install with that prefix isn't safe). If you post a new question about making pybind11 use the new CMake, it will be easier to figure out and others may see it and help. – Eliah Kagan Aug 04 '17 at 09:17
  • 2
    I installed cmake via this and make works now.. Thanks for the help :) – Surabhi Verma Aug 04 '17 at 10:16
  • @SurabhiVerma Good idea--I wish I had thought of using update-alternatives for this! :) I'm glad the problem is solved. – Eliah Kagan Aug 04 '17 at 10:20
  • I think it is not necessary to do uninstall as root. – Felix Crazzolara Oct 04 '19 at 16:53
  • Thanks!! help me a lot – Salvador Vigo Nov 17 '20 at 09:47