How to keep only ubuntu-minimal?

16,303

Solution 1

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.

Solution 2

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:
16,303

Related videos on Youtube

Josh
Author by

Josh

I`m an Ubuntu enthusiast who likes the web in general. I think linux in general is the base for the Internet. Therefore I like to learn as lot as I can about Linux Web techniques and all related stuff that fits into my leaky brain. Currently I try to develop an automated installer for a Drupal Development Server based on Ubuntu 14 LTS and extend this basic system with basic features like ftp or even a desktop Chooser and so on. If you like o take a look go to https://horvan.github.io/drubuntu

Updated on September 18, 2022

Comments

  • Josh
    Josh over 1 year

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

  • Oxwivi
    Oxwivi over 9 years
    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?
  • tumbleweed
    tumbleweed over 9 years
    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.
  • Oxwivi
    Oxwivi over 9 years
    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?
  • tumbleweed
    tumbleweed over 9 years
    Yes, you could do that.
  • SystemParadox
    SystemParadox over 6 years
    Could you add an example for markauto excluding multiple packages? The syntax of aptitude is rather confusing. A brief explanation of the pattern syntax used would be really helpful.
  • PowerKiKi
    PowerKiKi almost 6 years
    This saved me from a do-release-upgrade that went very wrong with a lot of dependencies conflicts. Removing almost everything this way, and then installing ubuntu-desktop made it as close as a fresh install as can be.