Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove and purge all packages installed by apt-get?

Tags:

debian

apt-get

I've tried apt-get --purge autoremove, but this is different. I want to completely wipe out the system. I've messed up with dependencies, and now there are tons of conflicts in there. Sure I can reinstall the whole OS, but that is exactly what I don't want to do for now.

Tip:

dpkg --list gives all installed packages. Can we purge this one by one and remove them?

dpkg --get-selections may be handy if you want to freeze your currently installed packages. You probably also mark them as "important", so you can save your initial setup in the beginning of the installation. And then remove all packages with a script provided in the selected answer :)

like image 935
holms Avatar asked Aug 12 '13 14:08

holms


1 Answers

You can do that. Just be careful not to remove essential packages, like dpkg and libc6, else your system will end up being unusable. The following script, which depends on python3-apt, should help:

#!/usr/bin/python3

import apt

cache = apt.cache.Cache()
for package in cache:
    if (package.is_installed and
        package.candidate.priority not in ("required", "important")):
        print(package.name, end=" ")
print()
like image 192
tshepang Avatar answered Oct 14 '22 12:10

tshepang