Managing your Debian packages with debfoster

Command Line – debfoster

© Lead Image © konstantynov, 123RF.com

© Lead Image © konstantynov, 123RF.com

Article from Issue 236/2020
Author(s):

When it comes to weeding out unnecessary packages on your Debian system, debfoster lets you conveniently arrange all your housekeeping functions into a single command.

Debian was one of the first distributions to have a modern package system. Over the decades, a whole ecosystem of related commands has grown up around it, including front ends like apt-get and, more recently, apt for the basic package manager dpkg, and then utilities ranging from apt-file for searching files inside packages to apt-cache for searching packages. In fact, a search on "apt" in the Stable repository for Debian 10 returns 54 hits, while a search on "deb" returns 68. One of the lesser-known but handier members of this ecosystem is debfoster [1], whose main purpose is to weed out unnecessary packages. However, like apt, debfoster actually combines several other functions, displaying information on currently installed packages, and serving as a replacement for apt-get.

You can start to use debfoster by running the command without options or targets to create a database of packages that you want to keep installed. This first session takes at least 20 minutes on an average system, since every installed package is queried. However, once the database is populated, later sessions generally only refer to a handful of packages. If you find that you have accidentally kept a package – which is easy to do the first time as your responses become automatic – you can exit and try again.

Once the database is created, debfoster can be run in two ways: by running it after packages have been installed or removed or as an alternative means to install and remove packages. To install a package, use the structure alongside another command with debfoster PACKAGE(S). To remove packages, add a minus sign (-) before the list of packages.

Either way, debfoster concludes by detecting orphans: packages that were installed as a dependency, but are no longer needed because of changes to the system. apt-get and apt, of course, perform the same function, but only give the choice of using the autoremove sub-command to delete them. By contrast, debfoster gives a wider variety of choices (Table 1). For one thing, the default is to keep the package (Figure 1), while apt-get and apt simply keep repeating their message about orphans each time they start. For another, you can choose to delete only the package (n) or its dependences as well (p) or view package information (i) before a decision is made. Similarly, you can exit debfoster instead of answering, committing the changes already indicated or without saving any of them. More importantly, many packages have no dependencies and are not detected by the basic package manager as orphans, and these may linger long after they are no longer wanted. All in all, debfoster offers a more hands-on, less accident-prone approach to package management that advanced users may appreciate.

Table 1

debfoster Response Choices

y

Yes

Keep the package (default)

n

No

Delete the package

p

Prune

Also deletes any package dependencies; a list of these packages displays above the prompt

s

Skip

Will be asked again the next time debfoster runs

h

Help

Summary

i or ?

Information

Displays package details

u

Undo

Works on last response

q

Quit

No packages removed; all changes lost

x

Exit

Makes changes to debfoster database that are already committed, removes unwanted packages, and exits without asking further questions

Figure 1: debfoster provides options (Table 1) to display information useful for package management.

Command Options

debfoster's options begin with a number of queries about installed packages. --show-keeper (-a) lists files to be kept (Figure 2), --show-orphans (-s) lists dependencies that are no longer needed (Figure 3), --show-depends PACKAGE (-d) or --show-related PACKAGE (-r) lists the packages that the specified package depends on (Figure 4), and --show-providers PACKAGE (-p) lists the package for which the specified package is installed only as a dependency – something that rarely happens in recent releases. More likely, --show-providers may return a message of Installed Package or Not a Dependency, which limits its usefulness. The other query options, though, are useful for knowing what packages to keep. The number of orphans can be particularly surprising, especially if you install packages from outside the official repositories.

Figure 2: debfoster creates a database of keepers – files not to remove.
Figure 3: Orphans are packages that were dependencies of a removed package.
Figure 4: debfoster can list a package's dependencies.

Other options affect how debfoster runs. To guard against mistakes, --mark-only (-m) does a dry run so you can see the results of your answers before anything is deleted. If you decide the results contain no surprises, then you can run debfoster with the --force (-f) option to have all deletions made. You can also run it with --quiet (-q) to assume that all answers are Yes, in order to update the keepers list. Should you be transferring files from one machine to another, you may want to use --config FILE (-c) to create a clean configuration file (see below) or --keeperfile FILE (-k) to create a clean database and then replace the transferred files with the newly-created ones. In addition, the usual --verbose (-v) option can sometimes give you a more detailed look at what is happening.

In its role as an apt-get or apt replacement, debfoster can also take --upgrade (-u), with or without packages specified.

Configuring debfoster

The default configuration file for debfoster is /etc/debfoster.conf. All fields in the file are case-insensitive, and the most commonly used fields (Table 2) are first in the file. If desired, an alternate configuration file can be specified using the option --config FILE (-c). Half a dozen fields are the commands for which debfoster is a front end. For the most part, these fields do not need to be changed, although if you are in the habit of using apt, you probably want to change InstallCmd's value to apt install.

Table 2

Configuration Fields and Their Defaults

Field

Default

Meaning

InstallCmd

apt-get install

Standard installation command

RemoveCmd

apt-get --purge remove

Standard command for removing packages

InfoCmd

dpkg -s

Standard command to review information on a single package

KeeperFile

/var/lib/debfoster/keepers

The file where the list of orphans is stored

DpkgStatus

/var/lib/dpkg/status

The file that lists information about which packages are at least partly installed

DpkgAvailable

/var/lib/dpkg/available

The file that lists available packages

MaxPriority

standard

Sets status of packages about which to ask questions. By default, questions will be asked about packages with the priorities standard, optional, and extra. Packages with a status of required or important are not queried by default. Setting the field to any means all packages will be queried

UseHold

yes

Will not upgrade packages with the hold attribute

UseEssential

yes

Will not remove packages marked as essential

UsePreDepends

yes

Dependencies will be installed along with the package

UseRecommends

yes

Packages installed with recommended packages

UseSuggests

no

Suggested packages will not be installed

UseTasks

no

Makes packages grouped using tasksel appear as packages named task-LABEL. Tasks cannot be removed, but no questions will be asked about them

KeepSections

 

Takes a comma-separated list of packages that should always be kept

NokeepSections

 

List the sections you are never interested in (e.g., possibly lib)

GuessDepends

 

List name extensions for packages that you want to group with their based packages (e.g., doc or dev)

NegativeKeepers

yes

Remembers explicit removals of packages. If a package that has been removed is then reinstalled, it is removed again without asking. Set to no to be asked before subsequent removals

Verbose

no

Get detailed information about operations, as with the -v option

Force

no

No questions are asked when the package is removed, as with the -f option

Quiet

no

No interaction on any packages, as with the -q option

Other fields can affect how debfoster operates. Some fields, like MaxPriority or UseHold are based on package settings, while others like Verbose or Quiet set options for debfoster command. Fields in /etc/debfoster.conf can be overwritten by command-line options, particularly --ignore-default-rules (-i), which suppresses the settings for the UseHold, UseEssential, MaxPriority, KeepSections, and NokeepSections fields.

A Convenient Arrangement

debfoster adds nothing new to the Debian package manager. Its functions are spread over a number of different commands. Rather, its strength lies in its convenient rearrangement of functions in a single command. Moreover, aside from the number of possible answers to questions, it is quick to learn, with options that most command-line users will have seen in other commands. As a result of these advantages, using it can tell you things about your packages that you could find elsewhere, but probably won't, because to do so is inconvenient. If you care about running as lean a system as possible, debfoster quickly justifies the few minutes needed to learn its basic workings.

The Author

Bruce Byfield is a computer journalist and a freelance writer and editor specializing in free and open source software. In addition to his writing projects, he also teaches live and e-learning courses. In his spare time, Bruce writes about Northwest coast art (http://brucebyfield.wordpress.com). He is also co-founder of Prentice Pieces, a blog about writing and fantasy at https://prenticepieces.com/.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Free Software Projects

    Free software covers such a diverse range of utilities, applications, and other assorted projects that it can be hard to find the perfect tool. We pick the best of the bunch. This month, we discuss Ubuntu, Debfoster, and Deborphan.

  • Command Line: Apt-get

    Dependency tangles fall away with the Debian package system.

  • Smart Package Manager

    The package manager is one of the central components on any Linux system. If you have a system with unreliable package management – such as Suse Linux 10.1 – you may want to consider the Smart alternative.

  • Installing Software

    We provide an introduction to installing and managing RPM packages.

  • Getting Rid of Old Kernels

    When you update the kernel, the old version remains on the disk. If you clean up, the reward is several hundred megabytes of free disk space.

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95

News