Debian-based Linux distributions like Ubuntu and Linux Mint rely on sophisticated package managers to automate the process of installing, upgrading, configuring, and removing software. The core package management tools in Debian are dpkg and apt.
This in-depth guide will explain the role of each tool and how they fit together to empower software control in Debian Linux:
The Role of dpkg: Low-Level Debian Package Manager
At the most basic level, the dpkg utility allows users to install, remove, and query individual .deb packages on a Debian system:
- Install .deb packages with
dpkg -i - Remove packages using
dpkg -r - List installed packages with
dpkg -l - Inspect packages with
dpkg -s
For example:
$ dpkg -i myapp_1.2.3_amd64.deb$ dpkg -r myapp
$ dpkg -l myapp
$ dpkg -s myapp
dpkg only manipulates individual packages and does not handle dependencies itself. If a package requires other packages, the user would need to manually ensure those are installed first.
This makes dpkg good for querying low-level package details but inconvenient for end users installing software. Checking and managing dependencies becomes complex and tedious.
Introducing apt: Automatic Dependency Resolution
The apt tools are designed to solve this key issue – dependencies management. apt acts as a frontend to dpkg by providing tools like:
- apt-get – command line interface for package tasks
- apt-cache – query available packages
- aptitude – ncurses interactive interface
The main advantages of using apt rather than dpkg directly are:
- Automatic dependency resolution – apt handles all dependencies for a package automatically
- Repository management – Software sources and packages are kept updated
- Easier interfaces – User friendly output and intuitive commands
Let‘s see an example installing the popular web browser Firefox with apt versus dpkg.
Installing Firefox with dpkg
If we try to install Firefox with dpkg:
$ dpkg -i firefox_76.0.1_amd64.deb
The operation will fail because the required dependencies are missing:
dpkg: dependency problems prevent configuration of firefox: firefox depends on libgtk-3-0 (>= 3.9.10); however: Package libgtk-3-0 is not installed.dpkg: error processing package firefox (--install): dependency problems - leaving unconfigured Errors were encountered while processing: firefox
To make this work, the user would need to somehow identify each missing dependency, find the required version, download the correct .deb packages, and manually install them first. Tedious!
Let‘s try with apt instead
The apt tools automatically handle dependencies seamlessly:
$ apt install firefox Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: fontconfig-config fonts-dejavu-core hunspell-en-us libasound2 libasound2-data libatk1.0-0 libatk1.0-data libatspi2.0-0 libcairo-gobject2 libcairo2 libdbus-1-3 libdrm-common libdrm2 libffi6 libfontconfig1 libfreetype6 libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-common libgl1 libgl1-mesa-dri libglib2.0-0 libglib2.0-data libgtk-3-0 libgtk-3-common libharfbuzz0b libice6 libjbig0 libjpeg-turbo8 libjpeg8 liblzma5 libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libpixman-1-0 libpng16-16 libsndfile1 libthai0 libtiff5 libx11-6 libx11-data libxau6 libxcb-dri2-0 libxcb-dri3-0 libxcb-present0 libxcb-render0 libxcb-shm0 libxcomposite1 libxcursor1 libxdamage1 libxfixes3 libxi6 libxinerama1 libxrandr2 libxrender1 libxshmfence1 libxtst6 shared-mime-info xdg-utils
Thanks to apt intelligently resolving dependencies, we installed Firefox and 35 other needed packages automatically with one simple command.
This is why apt is a substantially easier and more practical tool for end users doing package management in Debian/Ubuntu.
Now let‘s explore common package management tasks using apt tools in more depth.
Managing Packages in Depth with Apt Tools
While apt simplifies things, there is still a set of essential commands and options to learn for proficiency at handling packages on Debian-based systems.
Searching for Packages
Finding packages to install requires searching available repositories:
$ apt search firefox Sorting... Done Full Text Search... Done firefox/jammy 85.0.2+build1-0ubuntu0.22.04.1 amd64 Safe and easy web browser from Mozilla firefox-locale-en/jammy 85.0.2+build1-0ubuntu0.22.04.1 all English language packages for Firefox [...]
Helpfully, apt search lets us match both package names and descriptions. Some useful patterns include:
apt search ^firefox– Match names starting with firefoxapt search -n firefox– Just match package namesapt search --names-only firefox– Same as aboveapt search ‘.*server.*‘– Regex match descriptions
The apt-cache tool provides similar search capabilities:
$ apt-cache search docker | head -5 docker-ce - Docker: the open-source application container engine docker-ce-cli - Docker CLI: the open-source application container engine docker-compose-plugin - Docker Compose Plugin for Docker App docker.io - System tray for KDE3/GNOME2 docklet applications dogsled - POSIX shell framework for automated server provisioning
Between apt search and apt-cache search, we have powerful options to find packages we need.
Listing Installed Packages
Now let‘s switch gears to querying packages already installed on our system:
$ apt list --installed Listing... Done accountsservice/now 0.6.55-0ubuntu12+deb11u1 amd64 [installed] acl/now 2.3.1-2 amd64 [installed,automatic] acpi-support/now 1.0.6 amd64 [installed] acpid/now 2.0.33 amd64 [installed] adduser/now 3.118.4 all [installed] [...]
Helpful variants include:
apt list --upgradable– List packages with updatesapt list --manual-installed– Only manually installed packagesapt list --automatic– Only automatically installed packages
We can combine the list options too:
$ apt list --installed --manual-installed | head -5 accountsservice acl acpi-support acpid adduser
And as usual, apt-cache provides very similar functionally for listing installed packages:
$ apt-cache pkgnames accountsservice acl acpi-support acpid adduser [...]
Between apt list and apt-cache pkgnames, we can easily track our installed packages.
Upgrading Packages
Upgrading packages involves:
- Updating package repository metadata with
apt update - Upgrading packages with
apt upgrade
For example:
$ apt update Get:1 http://deb.debian.org/debian bullseye InRelease [122 kB] Get:2 http://deb.debian.org/debian bullseye/main amd64 Packages [8152 kB] Get:3 http://deb.debian.org/debian bullseye/main Translation-en [5152 B]$ apt upgrade Reading package lists... Done Building dependency tree... Done
Reading state information... Done Calculating upgrade... Done The following packages will be upgraded: base-files bsdutils coreutils debian-security-support gcc-10-base gcc-9-base krb5-locales libc-bin libc6 libgcc-s1 libkrb5-3 libsqlite3-0 libss2 openssl publicsuffix 17 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Need to get 8488 kB of archives. After this operation, 3072 B of additional disk space will be used. Do you want to continue? [Y/n]
This ensures we stay on the latest package versions available.
Some key points around apt upgrading:
- Use
apt full-upgradeto handle dependency changes - Add
-yto avoid manual confirmation prompts - Upgrade specific packages like
apt upgrade package1 package2
Learning proper upgrade workflows keeps systems up-to-date and secure.
Installing and Removing Packages
The bread and butter of package management – installing and removing software!
To install a package (and dependencies) simply use:
$ apt install apache2
Similarly, removing is a breeze with apt:
$ apt remove apache2
Common usage notes include:
- Add
-yto avoid confirmation prompts apt purgeto remove configurations too- Use exact package names for best results
Let‘s see some examples:
$ apt install -y htop glances python3-pip
$ apt purge -y apache2
Straightforward package installation and removal keeps systems lean and minimized.
APT Preferences and Pinning Packages
Customizing how apt handles packages enables advanced configuration scenarios.
Two key concepts here are APT preferences and package pinning.
Let‘s see some examples where these come in handy:
Package: * Pin: release a=testing Pin-Priority: 700Package: postgresql Pin: release a=testing Pin-Priority: 800
Package: kubeadm Pin: version 1.24* Pin-Priority: 1001
The possibilities get very sophisticated – perfect for sysadmins managing servers!
I suggest reviewing the man apt_preferences and man apt_pinning manuals for incredibly detailed documentation on custom package handling logic with apt.
Comparing APT Frontends: apt-get vs aptitude
Up until now, usage examples primarily showed apt-get and core apt commands. But earlier we also mentioned aptitude as another frontend available.
Let‘s elaborate on how aptitude compares.
The aptitude frontend provides an interactive, full-screen ncurses interface for browsing and manipulating packages. Experienced Linux users may find this familiar.
Some of the unique advantages offered by aptitude include:
- Visual package review during install/remove
- Group packages by state like installed, not installed, upgradeable
- Resolve package conflicts intelligently
- More detailed dependency visualization
To launch the interface simply run:
$ sudo aptitude
You will be greeted by something like:
aptitude 0.8.10 State -------- Not installed Configured? bags pc
[ See 2 broken packages ]
? dwarves pc
? okular pcCommands: Use the following commands to manage packages:
i, install - Mark additional packages for installation u, update - Update list of available packages g, upgrade - Upgrade installed packages f5, fix-broken - Try to fix broken packages or dependencies F10, quit - Quit
The interactive aptitude interface takes some practice to master. I suggest playing around to get comfortable – it can be an extremely efficient way to search, review, and manage packages.
But for most tasks, the simplicity and predictability of apt-get and apt make them preferable choices in my experience.
Summary: Choosing Apt Over Dpkg for Package Management
In this comprehensive walkthrough, we explored layers of technical detail across dpkg, apt, apt-get, and aptitude.
But let‘s zoom back out to recap the central high order takeaways:
- dpkg – Low-level package tool, key for querying and debugging
- apt family – Easier to use, advanced functionality, default choice
- apt vs apt-get – apt slightly preferred over apt-get
- aptitude – Interactive ncurses interface, niche usage
For nearly any common package management task on a Debian Linux system – installing tools, managing configurations, upgrading systems – reach for apt or apt-get first.
The commands should feel natural after grasping core concepts like repositories, dependencies, and pinning. Systems administrators can take advanced configuration like priorities and preferences to new levels.
I hope you feel empowered now to leverage Debian‘s exceptional packaging ecosystem to wrangle any server or desktop environment with confidence and precision. The journey to mastery never ends with so much depth and flexibility to explore!


