What's the opposite of 'make install', i.e. how do you uninstall a library in Linux?

后端 未结 12 579
旧巷少年郎
旧巷少年郎 2020-11-28 17:08

While running

./configure --prefix=/mingw 

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

\'./configure --pref         


        
相关标签:
12条回答
  • 2020-11-28 17:34

    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.

    0 讨论(0)
  • 2020-11-28 17:34

    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.

    0 讨论(0)
  • 2020-11-28 17:39

    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!

    0 讨论(0)
  • 2020-11-28 17:44

    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".

    0 讨论(0)
  • 2020-11-28 17:51

    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.

    0 讨论(0)
  • 2020-11-28 17:52

    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.

    0 讨论(0)
提交回复
热议问题