Removing alternative Ubuntu flavors completely

When Ubuntu users want to try other Ubuntu flavors, e.g. Xubuntu and Lubuntu, they usually just install their meta packages:

$ sudo apt-get install xubuntu-desktop

or

$ sudo apt-get install lubuntu-desktop

apt-get can install their dependencies automatically. However, when users want to remove the alternative Ubuntu flavors completely, they are out of luck, because inter-dependencies among many packages can be rather complex, and apt tools simply does not automatically remove the dependencies of meta packages.

A nice solution to this problem is to find out installed packages by parsing the dpkg log file: /var/log/dpkg.log.  Of course, the prerequisite is that you still have the log of your *ubuntu meta package installation session lying around.

I installed Xubuntu between “2015-09-26 20.12.30” and “2015-09-26 20:18:03” last night. The dpkg log of the installation session goes as follows:

2015-09-26 18:44:11 status half-configured gnome-menus:i386 3.10.1-0ubuntu2
2015-09-26 18:44:11 status installed gnome-menus:i386 3.10.1-0ubuntu2
2015-09-26 20:12:30 startup archives unpack
2015-09-26 20:12:37 install desktop-base:all <none> 7.0.3ubuntu1
2015-09-26 20:12:37 status half-installed desktop-base:all 7.0.3ubuntu1
2015-09-26 20:12:37 status triggers-pending hicolor-icon-theme:all 0.13-1
... ...
2015-09-26 20:18:03 trigproc menu:i386 2.1.46ubuntu1 <none>
2015-09-26 20:18:03 status half-configured menu:i386 2.1.46ubuntu1
2015-09-26 20:18:03 status installed menu:i386 2.1.46ubuntu1
2015-09-26 20:30:51 startup archives unpack
2015-09-26 20:31:00 install audacious-plugins-data:all <none> 3.4.3-2

Later, I found Lubuntu suits my old Pentium-M laptop better and decided to remove Xubuntu completely. Here is command I used to parse dpkg.log for all the packages installed for xubuntu-desktop:

root@micky:~# sed -n '/^2015-09-26 20:12:30/,/^2015-09-26 20:18:03/p' /var/log/dpkg.log | awk '$3 ~ "install" {print $4}' | xargs
desktop-base:all gnumeric-common:all libgoffice-0.10-10-common:all libgoffice-0.10-10:i386 gnumeric:i386 libchamplain-0.12-0:i386 libchamplain-gtk-0.12-0:i386 libwv-1.2-4:i386 libabiword-3.0:i386 libxfce4util-common:all libxfce4util6:i386 xfconf:i386 libxfconf-0-2:i386 libxfce4ui-common:all libxfce4ui-1-0:i386 libexo-common:all libexo-helpers:i386 libexo-1-0:i386 libgarcon-common:all libgarcon-1-0:i386 libtagc0:i386 thunar-data:all libthunarx-2-0:i386 libtumbler-1-0:i386 libxfce4ui-2-0:i386 libxfcegui4-4:i386 exo-utils:i386 xfce4-panel:i386 xfce4-settings:i386 xfce4-session:i386 plymouth-theme-ubuntu-text:i386 libots0:i386 libtidy-0.99-0:i386 abiword-common:all abiword:i386 link-grammar-dictionaries-en:all liblink-grammar4:i386 abiword-plugin-grammar:i386 libgdome2-0:i386 libgdome2-cpp-smart0c2a:i386 libgtkmathview0c2a:i386 abiword-plugin-mathview:i386 apt-offline:all xfce4-notifyd:i386 blueman:i386 python3-pexpect:all catfish:all gigolo:i386 libgstreamer-perl:i386 gmusicbrowser:all gnumeric-doc:all gstreamer1.0-libav:i386 gtk-theme-config:i386 libdigest-crc-perl:i386 libgtk2-notify-perl:i386 libgtk2-trayicon-perl:i386 libintl-perl:all libjpeg-turbo-progs:i386 libjpeg-progs:i386 libkeybinder0:i386 libxfce4ui-utils:i386 libxfce4util-bin:i386 light-locker:i386 python-psutil:i386 light-locker-settings:all lightdm-gtk-greeter:i386 python3-psutil:i386 menulibre:all mousepad:i386 mugshot:all orage:i386 parole:i386 pastebinit:all pavucontrol:i386 plymouth-theme-xubuntu-logo:all plymouth-theme-xubuntu-text:all policykit-desktop-privileges:all shimmer-themes:all thunar:i386 thunar-archive-plugin:i386 thunar-media-tags-plugin:i386 thunar-volman:i386 ttf-punjabi-fonts:all tumbler-common:all tumbler:i386 xchat-common:all xchat:i386 xchat-indicator:i386 xfburn:i386 xfce4-appfinder:i386 xfce4-cpugraph-plugin:i386 xfce4-dict:i386 xfce4-indicator-plugin:i386 xfce4-mailwatch-plugin:i386 xfce4-netload-plugin:i386 xfce4-notes:i386 xfce4-notes-plugin:i386 xfce4-power-manager-data:all xfce4-power-manager:i386 xfce4-quicklauncher-plugin:i386 xfce4-screenshooter:i386 xfce4-systemload-plugin:i386 xfce4-taskmanager:i386 xfce4-terminal:i386 xfce4-verve-plugin:i386 xfce4-volumed:i386 xfce4-weather-plugin:i386 xfce4-whiskermenu-plugin:i386 xfce4-xkb-plugin:i386 xfdesktop4-data:all xfdesktop4:i386 xfwm4:i386 xscreensaver:i386 xubuntu-artwork:all xubuntu-community-wallpapers:all xubuntu-default-settings:all xubuntu-desktop:i386 xubuntu-docs:all xubuntu-icon-theme:all xubuntu-wallpapers:all ristretto:i386 xfce4-places-plugin:i386

If you feed the above output to apt-get through a pipe via xargs, apt-get would simply abort after pompting for confirmation, because its standard input is already connected to the pipe by xargs, and it cannot read key stokes from the terminal. Therefore, I had to copy and paste the output into a separate “apt-get purge” command:

root@micky:~# apt-get purge desktop-base:all gnumeric-common:all libgoffice-0.10-10-common:all libgoffice-0.10-10:i386 gnumeric:i386 libchamplain-0.12-0:i386 libchamplain-gtk-0.12-0:i386 libwv-1.2-4:i386 libabiword-3.0:i386 ... ...

Adding the “-y” option to the apt-get command, which causes apt-get to run non-interactively, is also feasible, but it’s not recommended unless you’ve confirmed what packages apt-get is going to remove.

If you have installed other Ubuntu flavors, you’d better re-install their meta packages to make sure their dependencies are met, because the “apt-get purge …” command above could have removed their dependencies:

root@micky:~# apt-get install lubuntu-desktop ubuntu-desktop

发表评论

电子邮件地址不会被公开。 必填项已用*标注