Home Command line utilities Debfoster – Keep Only Essential Packages In Debian And Ubuntu

Debfoster – Keep Only Essential Packages In Debian And Ubuntu

By sk
Published: Last Updated on 4.7K views

Today, we are going to learn about a lesser-known, yet useful utility for Debian and its derivatives such as Ubuntu and Ubuntu variants like Linux Mint. Say hello to "Debfoster" - a command line utility to keep only essential packages and delete the other packages which are no longer required. So, you can keep clean and minimal system all the time. The debfoster application is a wrapper program for apt and dpkg package mangers. It maintains a list of installed packages that were explicitly requested rather than installed as a dependency.

When you run it for the first time, it will create a list of installed packages and saves it in a file named keepers in /var/lib/debfoster/ directory. Debfoster will use this list to detect packages that have been installed only because other packages depended on them. If one of these dependencies changes, debfoster will take notice, and ask if you want to remove the old package. This way it helps you to maintain a clean system with the essential packages of your choice.

Keep Only Essential Packages In Debian And Ubuntu Using Debfoster

Debfoster is available in the default repositories. So, installation won't be a big deal. Run the following command to install Debfoster on any Debian-based systems:

$ sudo apt install debfoster

Once installed, we need to create a list of installed packages by running the following command:

$ sudo debfoster -q

The above command will add the currently installed packages in keepers file in /var/lib/debfoster/ directory. You can edit this file to remove the packages that you no longer want to have installed in your system.

Here is the contents of my keepers file.

$ cat /var/lib/debfoster/keepers

You should not remove the system-related and important packages from this file, such as Linux kernel, grub, Ubuntu-base, Ubuntu-desktop etc. Also, backup important configuration files that you manually edited.

Now, force the debfoster utility to remove the packages which are not listed in keepers file. To do so, run:

$ sudo debfoster -f

Debfoster will remove all packages which are not available in the keepers file along with their dependencies.

It also installs any missing packages that seem to be missing, thus forcing your system to comply with the debfoster database.

And, then you can run the following command once in a while after every time you added/removed packages to check if there are any orphaned packages or unwanted dependencies that need to be removed.

$ sudo debfoster

If you have installed/removed any packages, you will see an output something like below. As you see in the output, Screen package is not listed in my keepers list. Because, I installed it after creating the keepers list. So, debfoster asks me whether I want to keep this or not. If you're not sure what to do, type H to display the help section.

Keep screen? [Ynpsiuqx?], [H]elp: H

 Yes Keep screen. [default]
 No Delete screen.
 Prune Delete screen and the packages it is keeping installed.
 Skip Skip this question.
 Help Print this message.
 Info or ? Show information about screen.
 Undo Undo last response.
 Quit Exit without removing packages.
 Exit Remove unwanted packages and exit.

Keep screen? [Ynpsiuqx?], [H]elp:

Debfoster will display all the possible options. Type Y if you don't want to remove the packages. The screen package will now be added to the keepers file and Debfoster will not remove it in the future transactions, unless you manually removed it yourself using "apt-get remove screen" command. Type N to delete the screen package. Type P to delete screen and the packages it is keeping installed. Type info or ? to display the details of the package. Q to exit without removing the package. And, type E to remove the packages and exit.

Viewing packages in the Keepers list

To view the list of packages in the debfoster database, run:

$ debfoster -a

Here is the list of packages in my Ubuntu 16.04 LTS desktop.

The following packages are on the keeper list:
 account-plugin-aim brasero debfoster deja-dup-backend-gvfs dialog firefox-locale-en gdebi gir1.2-webkit-3.0 git hyphen-en-us indicator-multiload
 language-pack-gnome-en libarchive-extract-perl libcpan-meta-perl libmodule-build-perl libmodule-pluggable-perl libpackage-constants-perl libpod-latex-perl
 libreoffice-help-en-us libreoffice-style-human libterm-ui-perl libtext-soundex-perl libvisual-0.4-plugins linux-generic linux-headers-4.4.0-15-generic
 linux-image-extra-4.4.0-15-generic myspell-en-au myspell-en-gb myspell-en-za mythes-en-us oneconf openoffice.org-hyphenation openssh-server python-pip python3-smbc
 rhythmbox-plugin-cdrecorder rhythmbox-plugin-magnatune samba-common screen shutter ssh-askpass-gnome telepathy-idle thunderbird-locale-en-us ubuntu-desktop
 ubuntu-minimal ubuntu-sso-client-qt ubuntu-standard ubuntu-wallpapers-wily wbritish xserver-xorg-video-cirrus xserver-xorg-video-mach64 xserver-xorg-video-mga
 xserver-xorg-video-neomagic xserver-xorg-video-openchrome xserver-xorg-video-r128 xserver-xorg-video-savage xserver-xorg-video-siliconmotion
 xserver-xorg-video-sisusb xserver-xorg-video-tdfx xserver-xorg-video-trident

Use different keeper file

By default, debfoster will maintain the installed packages at /var/lib/debfoster/keepers file. You can, however, specify a different debfoster database (keepers file, of course) using -k flag like below.

$ debfoster -k <path-to-keeper-file>

Viewing orphaned packages

You don't always need to run "sudo debfoster" command to check for the orphaned packages. You can simply use -s flag like below to view if there are any orphaned packages.

$ debfoster -s
The following packages have been orphaned:
 tmux

As you see in the above output, I have one orphaned package. If it is necessary package and don't want debfoster to remove it, we can simply add it to the keepers file by running the following command:

$ sudo debfoster

It will ask you to keep tmux or not. If you keep the tmux in keepers file, simply type Y.

Keep tmux? [Ynpsiuqx?], [H]elp:Y

Alternatively, you can manually edit the keepers file and add tmux in the list.

$ sudo vi /var/lib/debfoster/keepers

Add tmux in it.

[...]
tmux

Type :wq to save an quit the file. Now, you will not see any orphaned packages when running "debfoster -s" command.

Please note that here orphaned package means a package which is not mentioned in the debfoster database. It doesn't mean the package is completely not necessary. For example, screen and tmux utilities are quite useful. So, we can add them to debfoster database.

Adding/removing packages

Since debfoster is a wrapper for apt-get and dpkg package managers, you can also use it to add or remove packages.

To install a package, run:

$ sudo debfoster screen

Now debfoster will run apt-get for you and install the specified package.

To remove a package, simply place a minus (−) directly after its name like below.

$ sudo debfoster screen-
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following packages will be REMOVED:
 screen*
0 upgraded, 0 newly installed, 1 to remove and 608 not upgraded.
After this operation, 972 kB disk space will be freed.
Do you want to continue? [Y/n]

Finding dependencies

To list all packages that a package depends on, use -d flag.

$ debfoster -d screen

And, to list all packages in the debfoster database that depend on the given package, use -e flag like below.

$ debfoster -e screen

For more details, refer the man pages.

$ man debfoster

As you can see, Debfoster helps you to keep track of what you've installed and remove all other packages which are not required. Again, I warn you - you must use this application very carefully. Don't remove important system-related packages like Ubuntu-base, grub, current Kernel etc. If you do, you may end up with an unusable system.


Suggested read:


Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

2 comments

Conrad December 24, 2019 - 10:03 pm

Doesn’t aptitude do all this?

Reply
sk December 25, 2019 - 12:48 pm

Yes, it does. Debfoster is just another tool to keep a clean Debian install all the time.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More