1. Introduction

Managing software packages in Linux involves overseeing collections of files that include applications, libraries, configuration files, and resources needed to operate software on a Linux system. This process includes tasks like installing, uninstalling, updating, checking packages, and handling dependencies. The goal is to maintain software operations and ensure system stability and security.

In this tutorial, we’ll compare dpkg and aptitude and explain when we should use one over the other.

First, we’ll see an overview of dpkg and aptitude. After that, we’ll explore the features of dpkg and aptitude. Lastly, we’ll view the difference between dpkg and aptitude.

2. Overview of dpkg and aptitude

To begin with, let’s get an overview of dpkg and aptitude.

dpkg is a fundamental package management tool in Debian-based Linux distributions. Its primary uses include installing, removing, and managing software packages. Additionally, it can provide package information, handle configuration files, verify package integrity, reconfigure packages, and extract package contents. Therefore, it only works directly with package files. However, it lacks some advanced features in higher-level package managers like apt or aptitude.

aptitude is a sophisticated package management tool used in Debian-based Linux systems. It facilitates package installation and removal, efficiently handles dependencies, and provides package searching capabilities. Hence, with its interactive interface, users can easily manage packages, track dependencies, and upgrade the system seamlessly. aptitude is a versatile tool streamlining package management tasks in Debian-based environments.

3. Features of dpkg

Now, let’s explore the features of dpkg in Linux.

3.1. Package Installation

We can install Debian packages onto the system using dpkg:

$ dpkg -i package.deb

Next, let’s install the cowsay package using dpkg:

$ sudo dpkg -i cowsay_3.03+dfsg2-4_all.deb
[sudo] password for kali: 
Selecting previously unselected package cowsay.
(Reading database ... 405387 files and directories currently installed.)
Preparing to unpack cowsay_3.03+dfsg2-4_all.deb ...
Unpacking cowsay (3.03+dfsg2-4) ...
Setting up cowsay (3.03+dfsg2-4) ...
Processing triggers for man-db (2.12.0-3) ...

In the above command, dpkg installs the specified Debian package file onto our system. We need to ensure we have the necessary permissions to install packages and that the package is compatible with our system.

3.2. Package Removal

Similarly, we can remove installed packages from the system with dpkg:

$ dpkg -r package_name

Now, let’s remove the cowsay package that we installed above using dpkg:

$ sudo dpkg -r cowsay
(Reading database ... 229238 files and directories currently installed.)
Removing cowsay (3.03+dfsg2-4) ...
Processing triggers for man-db (2.10.2-1) ...

Thus, using the dpkg command effectively removes the specified package from our system. Moreover, ensure that we possess the requisite permissions for package removal and verify that the package being removed is not essential to any other installed software.

3.3. Package Information

Next, we can use dpkg to get detailed information about installed packages.

Let’s get the detailed information on the cowsay package:

$ sudo dpkg -I cowsay*
 new Debian package, version 2.0.
 size 17684 bytes: control archive=2140 bytes.
     731 bytes,    17 lines      control              
    3530 bytes,    52 lines      md5sums              
 Package: cowsay
 Version: 3.03+dfsg2-4
 Architecture: all
 Maintainer: Ubuntu Developers <[email protected]>
 Original-Maintainer: Tony Maillefaud <[email protected]>
 Installed-Size: 87
 Depends: libtext-charwidth-perl, perl:any
 Suggests: filters, cowsay-off
 Section: games
 Priority: optional
 Homepage: https://web.archive.org/web/20120527202447/http://www.nog.net/~tony/warez/cowsay.shtml
 Description: configurable talking cow
  Cowsay (or cowthink) will turn text into happy ASCII cows, with
  speech (or thought) balloons. If you don't like cows, ASCII art is
  available to replace it with some other creatures (Tux, the BSD
  daemon, dragons, and a plethora of animals, from a turkey to
  an elephant in a snake).

Once the above command is executed, it retrieves and displays information about Debian packages that match the pattern cowsay*. In addition, it provides details such as package name, version, architecture, dependencies, maintainer information, description, and more without actually installing the packages.

3.4. Package Content

Subsequently, we can use the -c flag to get the package content.

Now, let’s view the content of the cowsay package:

$ dpkg -c cowsay*
drwxr-xr-x root/root         0 2017-11-22 22:17 ./
drwxr-xr-x root/root         0 2017-11-22 22:17 ./usr/
drwxr-xr-x root/root         0 2017-11-22 22:17 ./usr/games/
-rwxr-xr-x root/root      4664 2017-11-22 22:17 ./usr/games/cowsay
drwxr-xr-x root/root         0 2017-11-22 22:17 ./usr/share/
drwxr-xr-x root/root         0 2017-11-22 22:17 ./usr/share/cowsay/
drwxr-xr-x root/root         0 2017-11-22 22:17 ./usr/share/cowsay/cows/
-rw-r--r-- root/root       115 2017-11-22 22:17 ./usr/share/cowsay/cows/apt.cow
-rw-r--r-- root/root       310 1999-08-14 12:17 ./usr/share/cowsay/cows/bud-frogs.cow
-rw-r--r-- root/root       123 1999-08-14 12:17 ./usr/share/cowsay/cows/bunny.cow
-rw-r--r-- root/root      1127 2017-11-22 22:17 ./usr/share/cowsay/cows/calvin.cow
-rw-r--r-- root/root       480 1999-08-14 12:17 ./usr/share/cowsay/cows/cheese.cow
...........

The command given above lists the contents of Debian packages. Additionally, this command displays the files and directories they contain without extracting them, providing an overview of the package contents.

3.5. Lists All Installed Packages

dpkg lets us see the list of all the packages already installed on our system.

Let’s run the command in the terminal and view its result:

$ dpkg -l
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                       Version                         >
+++-==========================================-================================>
ii  accountsservice                            22.07.5-2ubuntu1.4              >
ii  acl                                        2.3.1-1                         >
ii  acpi-support                               0.144                           >
ii  acpid                                      1:2.0.33-1ubuntu1               >
ii  adduser                                    3.118ubuntu5                    >
ii  adwaita-icon-theme                         41.0-1ubuntu1                   >
ii  aisleriot                                  1:3.22.22-1                     >
ii  alsa-base                                  1.0.25+dfsg-0ubuntu7            >
ii  alsa-topology-conf                         1.2.5.1-2                       >
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                       Version                         >
+++-==========================================-================================>
ii  accountsservice                            22.07.5-2ubuntu1.4 
.............

The command dpkg -l provides a comprehensive list of all installed packages on a Debian-based Linux system. This list includes package names, versions, descriptions, and other relevant information. Additionally, it offers an overview of the installed software packages, aiding in system management and troubleshooting.

4. Features of aptitude

Now, we’ll explore the functionalities of aptitude in Linux.

4.1. Package Installation

Alternatively, we can also use aptitude to install packages.

Now let’s install the VLC player with aptitude:

$ sudo aptitude vlc
The following NEW packages will be installed:
  liba52-0.7.4{a} libaribb24-0{a} libcddb2{a} libdvbpsi10{a} libebml5{a}
  libixml11{a} liblirc-client0{a} libmad0{a} libmatroska7{a}
  libmpeg2-4{a} libopenmpt-modplug1{a} libprotobuf-lite32{a}
  libproxy-tools{a} libresid-builder0c2a{a} libsidplay2{a}
  libspatialaudio0{a} libupnp17{a} libva-wayland2{a} libvlc-bin{a}
  libvlc5{a} libvlccore9{a} libvncclient1{a} libxcb-composite0{a} vlc
  vlc-bin{a} vlc-data{a} vlc-l10n{a} vlc-plugin-access-extra{a}
  vlc-plugin-base{a} vlc-plugin-notify{a} vlc-plugin-qt{a}
  vlc-plugin-samba{a} vlc-plugin-skins2{a} vlc-plugin-video-output{a}
  vlc-plugin-video-splitter{a} vlc-plugin-visualization{a}
0 packages upgraded, 36 newly installed, 0 to remove and 434 not upgraded.
Need to get 14.4 MB of archives. After unpacking 70.5 MB will be used.
............

Once the command is executed, it searches for the vlc package using the aptitude package manager in Debian-based Linux distributions.

4.2. Dependency Handling

Also, we can use aptitude to track dependencies between packages, ensuring that installed packages are consistent and compatible with each other:

$ sudo aptitude install -f
No packages will be installed, upgraded, or removed.
0 packages upgraded, 0 newly installed, 0 to remove and 434 not upgraded.
Need to get 0 B of archives. After unpacking 0 B will be used.

The above command automatically resolves dependency issues and fixes broken packages during the installation process in Debian-based Linux systems. It ensures that missing dependencies are installed and broken dependencies are repaired, helping maintain a stable and functional system.

4.3. Package Searching

aptitude provides a convenient way to search for packages based on criteria such as package name, description, or keywords.

For instance, let’s search for the firefox package in our system:

$ aptitude search firefox
p   activity-aware-firefox         - wrapper to make Firefox aware of Plasma
p   firefox-developer-edition-en-u - Mozilla Firefox web browser - Developer
i A firefox-esr                    - Mozilla Firefox web browser - Extended S
p   firefox-esr-l10n-ach           - Acoli language package for Firefox ESR  
p   firefox-esr-l10n-af            - Afrikaans language package for Firefox E
p   firefox-esr-l10n-all           - All language packages for Firefox ESR (m
p   firefox-esr-l10n-an            - Aragonese language package for Firefox E
p   firefox-esr-l10n-ar            - Arabic language package for Firefox ESR
p   firefox-esr-l10n-ast           - Asturian language package for Firefox ES
p   firefox-esr-l10n-az            - Azerbaijani language package for Firefox
p   firefox-esr-l10n-be            - Belarusian language package for Firefox
p   firefox-esr-l10n-bg            - Bulgarian language package for Firefox E
p   firefox-esr-l10n-bn            - Bengali language package for Firefox ESR                              
p   firefox-esr-l10n-br            - Breton language package for Firefox ESR
p   firefox-esr-l10n-bs            - Bosnian language package for Firefox ESR
p   firefox-esr-l10n-ca            - Catalan language package for Firefox ESR
............

The search command allows us to use the aptitude package manager in Debian-based systems to find packages associated with Firefox. It presents a list of packages that match the search term firefox, providing descriptions and additional details, aiding in discovering and exploring Firefox-related packages on the system.

4.4. Interactive Interface

The aptitude provides an interactive command-line interface with menus and keyboard shortcuts, making it easy to navigate and perform package management tasks efficiently:

$ aptitude

When we use the command aptitude, it opens the aptitude package manager, allowing us to interact with it through a command-line interface on Linux systems based on Debian. This interface includes menus and keyboard shortcuts.

Hence, these features make navigating and efficiently performing various package management tasks convenient.

4.5. System Upgrade

Consequently, we can use aptitude to upgrade the entire system to the latest available packages, ensuring that all installed software is up-to-date:

$ sudo aptitude full-upgrade
The following NEW packages will be installed:
  gcr4{a} libgck-2-2{a} libgcr-4-4{a} libjq1{a} libonig5{a}
  python3-pyasyncore{a} python3-shtab{a}
The following packages will be REMOVED:
  libadwaita-1-0{u} libappstream5{u} libboost-dev{u} libboost1.83-dev{u}
  libopenblas-dev{u} libopenblas-pthread-dev{u} libopenblas0{u}
  libpython3-all-dev{u} libpython3.12{u} libpython3.12-dev{u}
  libstemmer0d{u} libxmlb2{u} libxsimd-dev{u} python3-all-dev{u}
  python3-beniget{u} python3-gast{u} python3-pythran{u}
  python3.12-dev{u} xtl-dev{u} zenity{u} zenity-common{u}
................

This command is used in Debian-based Linux systems to perform a comprehensive system upgrade. It upgrades all installed packages to their latest versions.

Furthermore, it resolves package dependencies and ensures the system is up-to-date with the latest software and security updates.

4.6. Package Removal

We can use the aptitude to remove unnecessary packages within our system.

Now, let’s uninstall the vlc package that was installed earlier using aptitude:

$ sudo aptitude remove vlc
The following packages will be REMOVED:  
  liba52-0.7.4{u} libaribb24-0{u} libcddb2{u} libdvbpsi10{u} libebml5{u}
  libixml11{u} liblirc-client0{u} libmad0{u} libmatroska7{u}
  libmpeg2-4{u} libopenmpt-modplug1{u} libprotobuf-lite32{u}
  libproxy-tools{u} libresid-builder0c2a{u} libsidplay2{u}
  libspatialaudio0{u} libupnp17{u} libva-wayland2{u} libvlc-bin{u}
  libvlc5{u} libvlccore9{u} libvncclient1{u} libxcb-composite0{u} vlc
  vlc-bin{u} vlc-data{u} vlc-l10n{u} vlc-plugin-access-extra{u}
  vlc-plugin-base{u} vlc-plugin-notify{u} vlc-plugin-qt{u}
  vlc-plugin-samba{u} vlc-plugin-skins2{u} vlc-plugin-video-output{u}
  vlc-plugin-video-splitter{u} vlc-plugin-visualization{u}
0 packages upgraded, 0 newly installed, 36 to remove and 434 not upgraded.
Need to get 0 B of archives. After unpacking 70.5 MB will be freed.
Do you want to continue? [Y/n/?]

Using the aptitude package manager, the command above uninstalls the VLC media player package from a Debian-based Linux system.
It removes all associated files, including configuration files, and frees up disk space previously occupied by the package.

4.7. Purge Package

Similarly, the aptitude purge feature removes package and configuration files from the system.

Next, let’s proceed with purging the vlc package from the system:

$ sudo aptitude purge vlc
The following packages will be REMOVED:  
  liba52-0.7.4{u} libaribb24-0{u} libcddb2{u} libdvbpsi10{u} libebml5{u}
  libixml11{u} liblirc-client0{u} libmad0{u} libmatroska7{u}
  libmpeg2-4{u} libopenmpt-modplug1{u} libprotobuf-lite32{u}
  libproxy-tools{u} libresid-builder0c2a{u} libsidplay2{u}
  libspatialaudio0{u} libupnp17{u} libva-wayland2{u} libvlc-bin{u}
  libvlc5{u} libvlccore9{u} libvncclient1{u} libxcb-composite0{u} vlc{p}
  vlc-bin{u} vlc-data{u} vlc-l10n{u} vlc-plugin-access-extra{u}
  vlc-plugin-base{u} vlc-plugin-notify{u} vlc-plugin-qt{u}
  vlc-plugin-samba{u} vlc-plugin-skins2{u} vlc-plugin-video-output{u}
  vlc-plugin-video-splitter{u} vlc-plugin-visualization{u}
0 packages upgraded, 0 newly installed, 36 to remove and 434 not upgraded.
Need to get 0 B of archives. After unpacking 70.5 MB will be freed.
Do you want to continue? [Y/n/?]

The above command thoroughly eliminates the VLC media player package from a Debian-based Linux system, encompassing its configuration files.

Hence, this action ensures that the package becomes absent from the system, restoring it to a state as if it had never been installed. This ensures a complete reset to the package’s default state or removes any residual files post-uninstallation.

Notably, when managing packages in Linux, if we remove a package, it’ll delete the files. Thus, the package’s configuration settings are retained. However, purging a package involves removing the files and configurations and resetting it to its default state.

5. Differences Between dpkg and aptitude

dpkg and aptitude are package management tools in Debian-based Linux distributions. However, they serve different purposes and have different features.

Now, let’s view some of the main differences between them.

5.1. Purpose

dpkg is a low-level package management tool that interacts directly with Debian package files *.deb. It handles tasks such as package installation, removal, and querying package information.

On the other hand, aptitude is a higher-level package management tool built on dpkg. It provides a more user-friendly interface for package management and offers additional features such as dependency resolution, an interactive interface, and system upgrades.

5.2. Level of Interaction

The dpkg primarily operates through the command-line interface or CLI and lacks an interactive interface.

aptitude provides an interactive CLI with menus and keyboard shortcuts, making navigating and performing package management tasks easier.

5.3. Dependency Resolution

The dpkg does not automatically handle dependencies. It installs packages directly but may only succeed if dependencies are met.

aptitude automatically resolves dependencies when installing or removing packages, ensuring that it installs or removes all required dependencies along with the package.

5.4. Features

The dpkg offers basic package management features such as installation, removal, querying package information, verification, reconfiguration, and extraction.

Conversely, aptitude provides additional features, including package searching, package management with an interactive interface, dependency tracking, system upgrades, and conflict resolution.

5.5. User Experience

Thus, dpkg offers a straightforward but less user-friendly interface suitable for more experienced users who prefer direct control over package management tasks.

Likewise, aptitude offers a more intuitive and user-friendly interface suitable for both novice and experienced users. Its features simplify package management tasks and provide more interactive control over the system’s package state.

5.6. Summary

In summary, dpkg is a foundational package management tool in Debian-based systems. It focuses on essential tasks like installation, removal, and information retrieval directly from Debian package files *.deb.

However, aptitude elevates the package management experience by offering a sophisticated interface with automatic dependency handling, interactive menus, system upgrades, conflict resolution, and package searching capabilities.  Moreover, its user-friendly approach caters to novice and experienced users, enhancing efficiency. Furthermore, it’s easy to use to manage software packages.

6. Conclusion

In this tutorial, we compared dpkg and aptitude and explained when we should use one over the other.

We initially gained an understanding of dpkg and aptitude, then explored their features, and finally examined the distinctions between them.