Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How can I remove all packages from Ubuntu and make sure ubuntu-minimal will not be lost?

share|improve this question

2 Answers 2

up vote 13 down vote accepted
+50

It's fairly easy with aptitude. First, make sure you have it and ubuntu-minimal installed:

sudo apt-get install aptitude ubuntu-minimal

Then, mark all packages as being automatically installed, except ubuntu-minimal:

sudo aptitude markauto '~i!~nubuntu-minimal'

After that, you should be left with only ubuntu-minimal, and the things it depends on.

WARNING: This doesn't include a kernel, so I suggest installing linux-image-generic immediately.

share|improve this answer
    
What is the significance of marking packages auto and why would it remove everything else? What else can the packages me marked as, and what would be their effects? –  Oxwivi Sep 10 at 15:55
    
Automatically installed packages that aren't depended on by manually installed packages are considered not needed. They are scheduled for removal automatically by aptitude, or can be manually removed with apt-get autoremove. –  tumbleweed Sep 22 at 9:01
    
I see. But isn't it possible to add multiple arguments there besides ubuntu-minimal to add linux-image-generic and any other package I decide I want to keep? –  Oxwivi Sep 25 at 18:19
    
Yes, you could do that. –  tumbleweed Oct 5 at 13:52

ubuntu-minimal is a metapackage. Its function is to have other packages as dependencies. Those other packages are the packages needed for a minimal system. ubuntu-minimal does not actually provide any files directly. If you tried to remove all packages except it, you would remove its dependencies too...which would not be what you want.

If you recently installed software atop a minimal system and now want to get back to the minimal system, that's shouldn't be too hard. If you remember what you installed, uninstall it. If you don't, look in your logs (if the installation was recent, /var/log/apt/term.log should do the trick).

You could try to figure out all the packages that are direct or indirect dependencies of ubuntu-minimal that are installed on your system. Some of the indirect dependencies (i.e., dependencies of dependencies, or even further removed) may be satisfiable by different alternatives, so it's not guaranteed that causing you to have all the packages a minimal system has when it's first installed would be the same thing as removing all your currently installed packages except those necessary to preserve ubuntu-minimal. It probably wouldn't be too big a difference, though.

Presumably something like this could be achieved, and with a minimum of hassle, by running all the removal commands here, here, here, and here (for 12.10; for another version, you'd remove all the packages list in the relevant section on that website).

  • If you wanted to attempt this, you'd run just the apt-get remove commands, not the commands afterwards that install packages or perform configuration. So near the end of each command, sudo apt-get install ... appears. Don't run that or anything after it.
  • Those commands are crafted to remove what's present in one Ubuntu flavor / desktop environment, except that which is present in another. There's plenty, but not total, overlap, and specifying the same package for removal multiple times isn't a problem.
  • Theoretically by running all of them you could get rid of all the packages associated with each desktop environment, without having to do the work of figuring anything out. However, this would keep everything that's simultaneously in Ubuntu, Kubuntu, Xubuntu, Lubuntu, and Edubuntu, and that includes a significant number of packages, including minimal GUI packages, that aren't present in a minimal command-line only system.
  • For a considerably less extreme version of this (four huge commands instead of sixteen), do just the "Remove Ubuntu" removals at the top of each of those four pages. Assuming you have a "vanilla" Ubuntu system, this should take care of most of your packages. Be aware, though, that it will likely leave more than the more extreme version.
  • At the end, it's important that you run sudo apt-get install ubuntu-minimal. It might be automatically removed to resolve dependencies removing other packages. The pages with the commands refer to a possible bug that would cause it to be removed when running them. And generally speaking it's best not even to assume metapackages are installed in the first place.
  • This might not work, and it might mess things up very badly. While it's unlikely you'd experience actual loss of documents from this:
    1. Back up your documents because they should always be backed up and you're running huge commands with sudo. If nothing else, you might paste in some other huge thing by accident that causes harm when run. :)
    2. Make sure you're prepared for your Ubuntu system to stop working completely. It might not boot. You should still be able to access its contents with a live CD/DVD/USB. Make sure to have one of those. (It's hard to try to repair the system using the alternate or minimal CD's.)

In the end, 'Call me V' is correct and you should just reinstall (though the minimal CD is just as good as the alternate CD, for installing a minimal system, and it's a considerably smaller download). Try the above suggestion for fun if you're willing to have it blow up in your face, but installing from scratch will be simpler, faster, and easier.

If you want someone to try to give you a better answer, detailing exactly what packages need to be removed, then you'll have to provide more information. At minimum, you should tell us what Ubuntu release you're using. But it would also help if you told us about all the packages on your system.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.