Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to uninstall all packages from homebrew, distribute, macports, pip?

Over the course of the year I've become more familiar with programming on OS X, and I think in my initial excitement I installed a whole bunch of things that I won't use and that pollute my development environment.

In particular, I find that with pip, brew, port, and easy_install, I've added all sorts of packages for all sorts of versions, and even for different systems (Snow Leopard and Mountain Lion).

So now, I was wondering if there was any way for me to start from scratch? I'd prefer to keep my files and programs, so no reinstalling the OS. If there is an easy way to mass uninstall packages for each of the four, that would help tremendously.

Thanks!

like image 928
Johnny W Avatar asked Oct 07 '22 02:10

Johnny W


1 Answers

pip and easy_install install the mostly the same thing (both are tools that install most of the same packages).

First get a list of all installed packages, as you might want to keep some:

$ pip freeze > packages.txt

This should be a fairly large file that lists most (if not all) packages that you have installed in your default system python.

Edit that file and delete those packages that you want to keep, so it contains only those you want to get rid of (and no other lines or comments), then adjust the following script:

#!/bin/bash

for plugin in $(cat packages.txt); do
    PLUGIN=$(echo "$plugin" | awk -F == '{print }')
    echo "Uninstalling $PLUGIN..."
    expect -c "spawn pip uninstall $PLUGIN
    expect {
        \"Proceed (y/n)?\" {
            send \"y\r\n\"
            expect {
                exit
            }
        }
    }"    
done

For macports, see the uninstalling guide and associated warnings.

For brew, see this superuser question

Coincidentally, that should tell you that such questions belong at superuser.com, and not on stackoverflow - which is for programming related queries.

Don't worry - someone will eventually move your thread there.

like image 95
Burhan Khalid Avatar answered Oct 13 '22 11:10

Burhan Khalid