3

Is it possible to perform an equivalent of apt-get autoremove with aptitude? If yes, how?

The Debian Administrator's Handbook says that aptitude "autoremoves" packages automatically, but this is not true (not always true). In my case (Ubuntu GNOME 16.04), I have a linux kernel which apt-get autoremove suggests to get me rid of:

§ sudo apt-get autoremove
[sudo] password for alexey: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  linux-headers-4.4.0-31 linux-headers-4.4.0-31-generic
  linux-image-4.4.0-31-generic linux-image-extra-4.4.0-31-generic
0 upgraded, 0 newly installed, 4 to remove and 0 not upgraded.
After this operation, 295 MB disk space will be freed.
Do you want to continue? [Y/n]

aptitude, however, does not care about it.


Here is the output of aptitude why linux-image-4.4.0-31-generic:

i   ubuntu-gnome-desktop         Depends    gdm3                                                      
i A gdm3                         Recommends xserver-xorg                                              
c   xserver-xorg                 Recommends xserver-xorg-video-all | xorg-driver-video                
p   virtualbox-guest-x11         Provides   xorg-driver-video                                         
p   virtualbox-guest-x11         Depends    virtualbox-guest-utils (= 5.0.32-dfsg-0ubuntu1.16.04.2)   
p   virtualbox-guest-utils       Recommends virtualbox-guest-dkms (= 5.0.32-dfsg-0ubuntu1.16.04.2) | v
                                            irtualbox-guest-source (= 5.0.32-dfsg-0ubuntu1.16.04.2) | 
                                            virtualbox-guest-modules                                  
i A linux-image-4.4.0-31-generic Provides   virtualbox-guest-modules

Here is the output of aptitude search '~i linux.*4.4.0-31' -F '%c%a%M %p':

i A linux-headers-4.4.0-31
i A linux-headers-4.4.0-31-generic
i A linux-image-4.4.0-31-generic
i A linux-image-extra-4.4.0-31-generic
  • What does aptitude why linux-image-4.4.0-31-generic output? – Stephen Kitt Feb 16 '17 at 22:38
  • @StephenKitt, i have added the output of aptitude why linux-image-4.4.0-31-generic. – Alexey Feb 18 '17 at 0:31
1

Automatic packages that are no longer used are marked as "id" in aptitude.

I find three ways to remove them.

  1. Aptitude UI

    sudo aptitude

    Press g to preview packages to be installed and removed.

    enter image description here

    You can find those packages under "Packages being removed because they are no longer used". Then press g again, aptitude will remove those packages.

  2. Aptitude command line with grep and xargs

    aptitude search ~i | grep ^id | awk '{print $2}' | xargs sudo aptitude purge -y

  3. Aptitude command line with Aptitude::Delete-Unused option

    sudo aptitude -o Aptitude::Delete-Unused=1 install

    Option: Aptitude::Delete-Unused

    Default: true

    Description: If this option is true, automatically installed packages which are no longer required will be automatically removed. For more information, see the section called “Managing automatically installed packages”.

    I found this solution from http://www.lambdacurry.com/2013/12/aptitude-equivalent-of-apt-get-autoremove/. And the option is described in "Configuration file reference" in the aptitude reference manual. I don't have enough reputation to post more links, so you can search around for the document.

Either of them works for me.

According to 6.2.7. Tracking Automatically Installed Packages:

With this information, when packages are removed, the package managers can compute a list of automatic packages that are no longer needed (because there is no “manually installed” packages depending on them).

and Managing automatically installed packages:

More precisely: they will be removed when there is no path via Depends, PreDepends, or Recommends to them from a manually installed package.

My answer applies only when there is no path of dependency (Depends, PreDepends, or Recommends) from a manually installed package to the target package. Thus there is no means of using aptitude to do the same thing as apt-get autoremove does in the situation described in the question (there exists a dependency path from ubuntu-gnome-desktop).

  • No, they are not marked for deletion. By the way, normally, to remove packages marked for deletion and to perform other pending actions, it is enough to run aptitude install. – Alexey Feb 18 '17 at 8:20
  • There is a clue in the footnote of Managing automatically installed packages, "they(auto installed packages) will be removed when there is no path via Depends, PreDepends, or Recommends to them from a manually installed package." Maybe that's the situation that you have met. aptitude why traces up to a manually installed package "ubuntu-gnome-desktop". I don't know whether aptitude treats the dependency valid even if the path is broken in the middle, but it seems to be the case. – lbs Feb 18 '17 at 16:08
  • Well, my question is how to reproduce apt-get autoremove with aptitude, because the behaviour of apt-get autoremove in my case works well for me. – Alexey Feb 18 '17 at 16:21
  • @Alexey, IMHO, aptitude doesn't seem to be able to do that in your situation because it still regards the dependency present. Hope someone would point out if I misunderstand that. I think I should add some limitations to my answer. – lbs Feb 18 '17 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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