430

While running

./configure --prefix=/mingw 

on a MinGW/MSYS system for a library I had previously run

'./configure --prefix=/mingw && make && make install' 

I came across this message:

WARNING: A version of the Vamp plugin SDK is already installed. Expect worries and sorrows if you install a new version without removing the old one first. (Continuing)

This had me worried. What's the opposite of 'make install', i.e. how is a library uninstalled in Linux? Will 'make clean' do the job, or are there other steps involved?

Alex Riley
  • 132,653
  • 39
  • 224
  • 205
  • http://serverfault.com/questions/422237/what-is-uninstall-procedure-for-software-installed-via-make-install-on-centos – Ciro Santilli新疆棉花TRUMP BAN BAD Jun 10 '15 at 12:48
  • 1
    See http://askubuntu.com/questions/87111/if-i-build-a-package-from-source-how-can-i-uninstall-or-remove-completely for similar answers, the main solution currently appears to be `sudo make uninstall` if the installation configuration files are still available but no other obvious solutions if not, apart from uninstalling with system package management utility if installed with "checkinstall" utility. – Edward May 14 '16 at 21:13
  • 8
    After running `make install` I've never needed `make uninstall` to remove them. I've always used `xargs rm < install_manifest.txt` – John Strood Jul 18 '16 at 13:47

13 Answers13

533

make clean removes any intermediate or output files from your source / build tree. However, it only affects the source / build tree; it does not touch the rest of the filesystem and so will not remove previously installed software.

If you're lucky, running make uninstall will work. It's up to the library's authors to provide that, however; some authors provide an uninstall target, others don't.

If you're not lucky, you'll have to manually uninstall it. Running make -n install can be helpful, since it will show the steps that the software would take to install itself but won't actually do anything. You can then manually reverse those steps.

Paweł Obrok
  • 21,259
  • 8
  • 72
  • 67
Josh Kelley
  • 50,042
  • 19
  • 127
  • 215
  • 12
    +1; Watch out for files that might also have been installed by other packages. Simply deleting these files (one interpretation of "manually reversing those steps") could break the other packages. This is (one of many reasons) why package managers were invented. – Merlyn Morgan-Graham May 10 '13 at 00:41
  • 4
    this is only possible if you keep the same configured and compiled build directory right? thus not very useful since most people would delete it after install. He wants to uninstall things regardless if he kept the build folder, and regardless if the package has been correctly configured for an make uninstall option. Clarification: what he wants to do is to enable some kind of management for packages that works for things he compiled himself. – Nisse Jul 27 '13 at 06:11
389

If sudo make uninstall is unavailable:

In a Debian based system, instead of (or after*) doing make install you can run sudo checkinstall to make a .deb file that gets automatically installed. You can then remove it using the system package manager (e.g. apt/synaptic/aptitude/dpkg). Checkinstall also supports creating other types of package, e.g. RPM.

See also http://community.linuxmint.com/tutorial/view/162 and some basic checkinstall usage and debian checkinstall package.


*: If you're reading this after having installed with make install you can still follow the above instructions and do a dpkg -r $PACKAGE_NAME_YOU_CHOSEN afterwards.

ndemou
  • 3,315
  • 1
  • 25
  • 29
Nisse
  • 4,067
  • 1
  • 10
  • 7
  • 58
    This answer is proof that the best answers often don't get a lot of up-votes. Thanks! I've wanted to know how to do this for a long time. I always hesitate doing a "make install" because I know it will almost certainly be a pain to remove. – doug65536 May 24 '13 at 18:53
  • 1
    also the LFS book has some information on package management systems, Since you have to set it up yourself. The information there should be helpful in getting this kind of thing work better(cleaner, more general). There are scripts that simply listen to what gets installed and then creates a script that when launched deletes all those files, or something like that. – Nisse Jul 27 '13 at 06:18
  • 14
    This worked beautifully for me, even though I already had run `make install` before using `checkinstall` instead. – LukeGT Mar 06 '14 at 07:43
  • 9
    Install package `checkinstall` for this excellent answer to work. – quimnuss Mar 30 '16 at 14:28
  • 1
    Similarly to what user "LukeGT" commented, if the installation configuration files are not available but the installer files are, they can be compiled and installed with `checkinstall` and if the new compilation is made with the same settings as the old one, uninstalling the package installed with `checkinstall` should remove the previously installed files. – Edward May 15 '16 at 12:09
  • Wow I will start hosting a bunch of custom debs thanks to this simple command. – nurettin Aug 14 '16 at 15:03
  • 3
    You can generate a `.deb` file without actually installing it using `checkinstall --install=no` – CK. Jun 16 '18 at 15:26
  • In order to get this to work, I had to specify a version number when `checkinstall` prompted me to change package values. – Feliks Montez Jul 24 '19 at 13:35
72

If you have a manifest file which lists all the files that were installed with make install you can run this command which I have from another answer:

cat install_manifest.txt | xargs echo rm | sh

If you have sudo make install you will need to add a sudo to your uninstall:

cat install_manifest.txt | xargs echo sudo rm | sh
three
  • 7,596
  • 3
  • 30
  • 37
  • 4
    I'm surprised to see this didn't get any upvotes. This worked to remove the files from the system when no other options worked. In my case, checkinstall couldn't create a deb because the version of the program did not start with a number, and therefore wouldn't build. This worked nicely. – DWils Mar 24 '14 at 07:51
  • 4
    @DWils I think it didn't receive more upvotes because it is quite dangerous. Additionally, `xargs echo rm | sh`? Quite obvious that whoever suggested this isn't particularly experienced or knowledgable in using the shell. – fstd May 03 '14 at 22:45
  • 4
    (for reference, it will barf on any characters in filenames which are interpreted by the shell (and then you have rogue 'rm's being executed!), additionally it will do all sorts of shell expansion. Just imagine what happens if the `install_manifest.txt` contains an asterisk... `rm *` will be piped into a shell.) Downvoted, for this reason. – fstd May 03 '14 at 22:47
  • @fstd quite right. As usual this kind of answer has to be used carefully. Check the manifest file before you run this command. But if you're using the shell I assume you know what you're doing. – three May 04 '14 at 21:17
  • 1
    Can you describe the circumstances under which an `install_manifest.txt` can be expected to exist? – einpoklum Jun 14 '18 at 11:33
  • hi, sorry, I don't remember. It's been more than four years ago and never had that problem again. I'm using arch and I still have to encounter an app or library that doesn't exist in the aur :) – three Jun 14 '18 at 17:55
  • Just modify this answer with: "Inspect install_manifest.txt thoroughly before executing the piped command". And: `cat install_manifest.txt | xargs -I {} rm '{}'` This handles rogue `*` as a filename, and also handles spaces in names properly. – TFuto Aug 26 '20 at 22:16
32

How to uninstall after "make install"

Method #1 (make uninstall)

Step 1: You only need to follow this step if you've deleted/altered the build directory in any way: Download and make/make install using the exact same procedure as you did before.

Step 2: try make uninstall.

cd $SOURCE_DIR 
sudo make uninstall

If this succeeds you are done. If you're paranoid you may also try the steps of "Method #3" to make sure make uninstall didn't miss any files.

Method #2 (checkinstall -- only for debian based systems)

Overview of the process

In debian based systems (e.g. Ubuntu) you can create a .deb package very easily by using a tool named checkinstall. You then install the .deb package (this will make your debian system realize that the all parts of your package have been indeed installed) and finally uninstall it to let your package manager properly cleanup your system.

Step by step

sudo apt-get -y install checkinstall
cd $SOURCE_DIR 
sudo checkinstall

At this point checkinstall will prompt for a package name. Enter something a bit descriptive and note it because you'll use it in a minute. It will also prompt for a few more data that you can ignore. If it complains about the version not been acceptable just enter something reasonable like 1.0. When it completes you can install and finally uninstall:

sudo dpkg -i $PACKAGE_NAME_YOU_ENTERED 
sudo dpkg -r $PACKAGE_NAME_YOU_ENTERED

Method #3 (install_manifest.txt)

If a file install_manifest.txt exists in your source dir it should contain the filenames of every single file that the installation created.

So first check the list of files and their mod-time:

cd $SOURCE_DIR 
sudo xargs -I{} stat -c "%z %n" "{}" < install_manifest.txt

You should get zero errors and the mod-times of the listed files should be on or after the installation time. If all is OK you can delete them in one go:

cd $SOURCE_DIR 
mkdir deleted-by-uninstall
sudo xargs -I{} mv -t deleted-by-uninstall "{}" < install_manifest.txt

User Merlyn Morgan-Graham however has a serious notice regarding this method that you should keep in mind (copied here verbatim): "Watch out for files that might also have been installed by other packages. Simply deleting these files [...] could break the other packages.". That's the reason that we've created the deleted-by-uninstall dir and moved files there instead of deleting them.


99% of this post existed in other answers. I just collected everything useful in a (hopefully) easy to follow how-to and tried to give extra attention to important details (like quoting xarg arguments and keeping backups of deleted files).

agc
  • 7,002
  • 2
  • 25
  • 44
ndemou
  • 3,315
  • 1
  • 25
  • 29
31

Depending on how well the makefile/configure script/autofoo magic of the program in question is the following might solve your problem:

make uninstall

The problem is that you should execute this on the source tree of the version you've got installed and with exactly the same configuration that you used for installing.

Joachim Sauer
  • 278,207
  • 54
  • 523
  • 586
10

make clean generally only cleans built files in the directory containing the source code itself, and rarely touches any installed software.

Makefiles generally don't contain a target for uninstallation -- you usually have to do that yourself, by removing the files from the directory into which they were installed. For example, if you built a program and installed it (using make install) into /usr/local, you'd want to look through /usr/local/bin, /usr/local/libexec, /usr/local/share/man, etc., and remove the unwanted files. Sometimes a Makefile includes an uninstall target, but not always.

Of course, typically on a Linux system you install software using a package manager, which is capable of uninstalling software "automagically".

mipadi
  • 359,228
  • 81
  • 502
  • 469
9

The "stow" utility was designed to solve this problem: http://www.gnu.org/software/stow/

jjw
  • 408
  • 3
  • 4
  • 6
    How would one go about using `stow` to solve this problem? – 3D1T0R Aug 11 '17 at 05:44
  • 1
    The stow utility encourages you to install each version to a separate location so that you can manage multiple versions on the same machine. If you do this then uninstalling can be as simple as deleting the entire installation directory. – Bruce Adams Feb 27 '19 at 17:42
6

There is no standard unfortunately, this is one of the perils of installing from source. Some Makefiles will include an "uninstall", so

make uninstall

from the source directory may work. Otherwise, it may be a matter of manually undoing whatever the make install did.

make clean usually just cleans up the source directory - removing generated/compiled files and the like, probably not what you're after.

Brenton Alker
  • 8,499
  • 2
  • 31
  • 37
3

Make

Make is the program that’s used to install the program that’s compiled from the source code. It’s not the Linux package manager so it doesn’t keep track of the files it installs. This makes it difficult to uninstall the files afterward.

The Make Install command copies the built program and packages into the library directory and specified locations from the makefile. These locations can vary based on the examination that’s performed by the configure script.

CheckInstall

CheckInstall is the program that’s used to install or uninstall programs that are compiled from the source code. It monitors and copies the files that are installed using the make program. It also installs the files using the Linux package manager which allows it to be uninstalled like any regular package.

The CheckInstall command is used to call the Make Install command. It monitors the files that are installed and creates a binary package from them. It also installs the binary package with the Linux package manager.

Replace "source_location.deb" and "name" with your information from the Screenshot.

Execute the following commands in the source package directory:

  1. Install CheckInstall sudo apt-get install checkinstall
  2. Run the Configure script sudo ./configure
  3. Run the Make command sudo make
  4. Run CheckInstall sudo checkinstall
  5. Reinstall the package sudo dpkg --install --force-overwrite source_location.deb
  6. Remove the package sudo apt remove name

Here's an article article I wrote that covers the whole process with explanations.

TheAltruist
  • 306
  • 2
  • 10
1

Method 1

From the source folder:

#make uninstall

Method 2

If there is no uninstall procedure:

  1. open install_manifest.txt (created by #make install)

  2. remove all the directories/files listed

  3. remove any remaining files you missed:

    #xargs rm < install_manifest.txt

  4. remove any hidden directories/files:

    $rm -rf ~/.packagename

Remove the source folder.

Method 3

If none of the above options work, view the install procedure:

#make -n install

and reverse the install procedure:

#rm -rf all directories/files created

Example

For example, this is how to uninstall nodejs, npm, and nvm from source:

How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)

which you can do using any of the above methods.

V Li
  • 66
  • 4
0

I know of few packages that support "make uninstall" but many more that support make install DESTDIR=xxx" for staged installs.

You can use this to create a package which you install instead of installing directly from the source. I had no luck with checkinstall but fpm works very well.

This can also help you remove a package previously installed using make install. You simply force install your built package over the make installed one and then uninstall it.

For example, I used this recently to deal with protobuf-3.3.0. On RHEL7:

make install DESTDIR=dest
cd dest
fpm -f -s dir -t rpm -n protobuf -v 3.3.0 \
 --vendor "You Not RedHat" \
 --license "Google?" \
 --description "protocol buffers" \
 --rpm-dist el7 \
 -m you@youraddress.com \
 --url "http:/somewhere/where/you/get/the/package/oritssource" \
 --rpm-autoreqprov \
 usr

 sudo rpm -i -f protobuf-3.3.0-1.el7.x86_64.rpm
 sudo rpm -e protobuf-3.3.0      

Prefer yum to rpm if you can.

On Debian9:

make install DESTDIR=dest
cd dest
fpm -f -s dir -t deb -n protobuf -v 3.3.0 \
-C `pwd` \
--prefix / \
--vendor "You Not Debian" \
--license "$(grep Copyright ../../LICENSE)" \
--description "$(cat README.adoc)" \
--deb-upstream-changelog ../../CHANGES.txt \
 --url "http:/somewhere/where/you/get/the/package/oritssource" \
 usr/local/bin \
 usr/local/lib \
 usr/local/include

 sudo apt install -f *.deb
 sudo apt-get remove protobuf

Prefer apt to dpkg where you can.

I've also posted answer this here

Bruce Adams
  • 3,435
  • 3
  • 27
  • 65
0

Make can tell you what it knows and what it will do. Suppose you have an "install" target, which executes commands like:

cp <filelist> <destdir>/

In your generic rules, add:

uninstall :; MAKEFLAGS= ${MAKE} -j1 -spinf $(word 1,${MAKEFILE_LIST}) install \
              | awk '/^cp /{dest=$NF; for (i=NF; --i>0;) {print dest"/"$i}}' \
              | xargs rm -f

A similar trick can do a generic make clean.

Mischa
  • 2,090
  • 20
  • 15
0

Preamble

below may work or may not, this is all given as-is, you and only you are responsible person in case of some damage, data loss and so on. But I hope things go smooth!

To undo make install I would do (and I did) this:

Idea: check whatever script installs and undo this with simple bash script.

  1. Reconfigure your build dir to install to some custom dir. I usually do this: --prefix=$PWD/install. For CMake, you can go to your build dir, open CMakeCache.txt, and fix CMAKE_INSTALL_PREFIX value.
  2. Install project to custom directory (just run make install again).
  3. Now we push from assumption, that make install script installs into custom dir just same contents you want to remove from somewhere else (usually /usr/local). So, we need a script. 3.1. Script should compare custom dir, with dir you want clean. I use this:

anti-install.sh

RM_DIR=$1
PRESENT_DIR=$2

echo "Remove files from $RM_DIR, which are present in $PRESENT_DIR"

pushd $RM_DIR

for fn in `find . -iname '*'`; do
#  echo "Checking $PRESENT_DIR/$fn..."
  if test -f "$PRESENT_DIR/$fn"; then
    # First try this, and check whether things go plain
    echo "rm $RM_DIR/$fn"

    # Then uncomment this, (but, check twice it works good to you).
    # rm $RM_DIR/$fn
  fi
done

popd

3.2. Now just run this script (it will go dry-run)

bash anti-install.sh <dir you want to clean> <custom installation dir>

E.g. You wan't to clean /usr/local, and your custom installation dir is /user/me/llvm.build/install, then it would be

bash anti-install.sh /usr/local /user/me/llvm.build/install

3.3. Check log carefully, if commands are good to you, uncomment rm $RM_DIR/$fn and run it again. But stop! Did you really check carefully? May be check again?

Source to instructions: https://dyatkovskiy.com/2019/11/26/anti-make-install/

Good luck!