Automatic packages that are no longer used are marked as "id" in aptitude.
I find three ways to remove them.
Aptitude UI
sudo aptitude
Press
g
to preview packages to be installed and removed.You can find those packages under "Packages being removed because they are no longer used". Then press
g
again, aptitude will remove those packages.Aptitude command line with grep and xargs
aptitude search ~i | grep ^id | awk '{print $2}' | xargs sudo aptitude purge -y
Aptitude command line with
Aptitude::Delete-Unused
optionsudo 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
).