Beginner’s guide to Debian package management

Package management is one of the fundamental features of a Linux system. The package management tools and the package format vary from distro to distro, but most distros use one of the two core tools.

The RPM packaging format and tools like rpm and yum are common for Red Hat Enterprise Linux-based distros (such as RHEL itself and Rocky Linux). The other major family utilized by Debian, Ubuntu, and related distros is the .deb packaging format and tools like apt and dpkg.

All these Debian Linux distros offer a vast number of package management systems that, in turn, provide access to an organized database of over 6000 packages.

Package management ideally expedites the task of package installation, upgrade, configuration and obsoletion. It also sorts out dependency-related issues by incorporating the dependency resolution features.

In this article, we will take you through how to use these Debian Management tools to delineate:

  • How to access package metadata or version and details when the package is uninstalled.
  • How to set up, remove, reinstall, and upgrade Debian packages.
  • How to find files or libraries of uninstalled packages.

Package management introduction

In the previous versions of Linux, packages were set up or added by grabbing the built-in source code from the project. After that, the users compiled the source code into runnable binaries that incorporate manual pages, libraries, config files, and so on to generate a required program. In a better scenario, the user may find the programs already compiled by someone else, and they only need to add them to the system.

The compiled program was a single file that contained multiple other files assembled for convenient distribution, well-known as the tarball. After setting up a program from a tarball, files spread across the Linux system in multiple appropriate folders and subdirectories like “/bin, /var, /usr/share/man,” and more.

Despite tarball’s easy-to-create nature, it had some complications like:

  • It did not have software metadata, making it challenging to fix bugs and update to a new version.
  • Tracking down the required dependencies.
  • The user was not well-versed with the config files and documentation located in the system. Moreso, it complicated the process of software removal.

To resolve these complications, Linux introduced an enhanced system for package management dividing all the Linux distros into incorporating one of the two major packaging formats(RPM and DEB). You don’t need to worry about the two packaging formats since this article will focus on Debian-based package management systems and derivatives of the Debian distro like Linux Mint, Ubuntu, and more.

From a user point of view, commands mainly offer the basic package management function. However,  DevOps have endeavored to make Linux user-friendly as other tools like GUI have complemented the basic tools. This conceals some of the complexities of the command-line tools from the user.

That said, this tutorial will focus on the essential tools, albeit we will mention some of the other tools you can pursue.

What are packages in a Linux system?

Let us kickstart the guide with this most fundamental question. Linux OS is ideally made up of 2 portions.

  • The first is the Linux kernel.
  • The second is software packages that function with the kernel to give a complete OS. These packages can be app software like word processors, text editors, GNU utilities like cron, bash, dd, e.t.c, or device drivers that converse with the hardware. It is vital to note that everything other than the kernel is a package in Linux.

Next, let us have a detailed look at what these packages encompass.

Contents of packages

The content of packages managed by these package managers comprises four chief components.

  • Config files
  • Binaries or the executable programs
  • Documentation and manuals
  • Metadata files containing the dependencies, signatures, version, and other relevant information

The process of setting up, updating, and uninstalling software can be mechanized by keeping the four components organized in an explicit format.

Since we have seen what packages are, let us proceed and look at how Debian package managers differ from each other.

Debian package managers

The DPM comprises multiple layers, the top layer consisting of commands from the apt family of tools, and the lower layer is of dpkg and associated tools. So let’s get started


This Debian package manager allows you to easily set up, remove, manipulate and upgrade software seamlessly. What dpkg does is download DEB package content to the system and notifies about the essential dependencies. This command is responsible for most of the “behind-the-scenes” work in Linux. dpkg interacts with the package themselves while apt provides additional housekeeping.


A compelling command-line tool that manages the setup and configuration of deb packages. This is probably the most often used member of the apt suite of packaging tools. Its sole purpose is interfacing with remote repos maintained by the distros packaging team and performing actions on the available packages. Furthermore, it superintends and downloads the imperative dependencies to give the latest software.

It also compares the dependencies and informs the users about the one’s not in use by any package that a user can remove. In general, apt is used to update the local cache and modify the live system.


A menu-driven, text-based interface for dpkg and Apt management functions. It is convenient for a non-graphical interface environment that eases user task performance. Aptitude uses apt-get libraries and issues more perks because of an interactive UI. The following section will focus on how to update the cache and system on Debian.

Update package cache and system

Updating packages in Debian refers to the process of resynchronizing the package index files from their sources on Debian Linux via the internet.

The remote repo your packaging tools depend on for package info is constantly updated. However, most if not all of the Linux package management tools are designed for historical purposes to work directly with a local cache of this info. As such, that cache needs to be periodically refreshed.

It is also good practice to update your local package cache every session before carrying out other package commands. This ensures that you are operating the current info about the available software. To update the local cache, use the apt command together with update as shown below:

sudo apt update

The above command will display an updated list of the available packages in the repos you are tracking.

Upgrade packages

The “apt” command differentiates between two upgrade formats. The first format can be utilized in upgrading any components that do not need component removal. This proves vital when you don’t want to remove any of the already set up packages under any circumstances. However, some updates necessitate replacing system components or doing away with conflicting files. This format of the apt command will ignore any updates that need package removal:

sudo apt upgrade

The second format will update all packages, including those that need package removal. This is often necessary as dependencies for packages alternate.

Most of the time, obsolete packages will be replaced with functional equivalents during the upgraded format, which is generally safe for use. Nevertheless, it is key to be keen on removing the packages in case some critical components are selected for removal. To perform this apt format, type:

sudo apt full-upgrade

This will upgrade all the packages on your system. Next, let us learn about package location.

Package location

The package setup from command-line(apt/apt-get) or Debian software center utilities takes place through downloading packages from one or more repos. An APT or Debian repo is a server or a local directory containing package files and their metadata readable by the APT tools.

Hence, the APT package management system maintains repos inside the main config file “/etc/apt/sources.list” on all the Debian-based distros. So at any point a user executes a command for package setup, the apt-get/apt command looks inside the “/etc/apt/sources.list” or “/etc/apt/sources.list.d” for repo URLs.

It then downloads the wanted software for installation. Moreover, the “source.list” file encompasses additional info about the repo for the software to set up. The user can manually append new repos in the “/etc/apt/sources.list.d” directory without editing the main config file. But, the names of the new repo files must go along with the “/etc/apt/source.list” format. cat the content of the /etc/apt/source.list file:

sudo cat /etc/apt/sources.list | less

The general syntax for each included repo is as follows:

deb http://repo.tld/ubuntu distro component
deb-src saucy-updates universe

Let us break down the syntax for better comprehension:

  • deb: This one represents the deb archive. It can either be deb that insinuates the .deb package or deb-src repos containing package source code.
  • http: //repo.tld/ubuntu: This one refers to the repo URL.
  • distro: This is the distro code name.
  • component: This one stands for the repo categories. For example, the default Ubuntu repo has four sections: main, restricted, multiverse, and universe.

The APT and other tools utilize a local database to ascertain installed packages. To maintain the local database, synchronize the info with the repo listed in the “sources.list” using the apt-get update command. For that, it is essential to carry out a local database update before each package installation or update.

Downloading and installing Debian packages

Linux setup spontaneously installs a set of packages that a user can further customize as per the use of the system, in essence, workstation or server. Also, the user might sometimes need to install new packages. Because of that, we will take our discussion further and look at the package Download and installation methods.

Searching for packages

The first and most crucial step when downloading and installing packages is to search your distros often repo for the packages you are up to.

Searching for packages is one operation that aims to the package cache for information. To attain this, use apt-cache search. Remember to ensure that your local cache is up-to-date using the sudo apt update before searching for packages using the following syntax:

apt-cache search <package>

Remember to replace the <package> with the actual package name.

For example, if you search for media types, you will see such results:

apt-cache search media-types

As seen in the snapshot above, you have a package named media-type, but you can also see several other programs, each of which explains media-types in the whole description field of the package.

Install packages from the repos

Install using APT-GET

To install a package from the repos, we will utilize the apt-get command with the install argument.

sudo apt-get install -s tmux
using apt get
using apt-get

Additionally, you can utilize the following syntax to install multiple packages at once, separated by a space:

sudo apt-get install package1 package2
Install using dpkg

If you download a .deb file with all the dependencies without apt-get, you can use the following command to set it up via dpkg.

sudo dpkg -i <packagename>.deb
Install using aptitude

This package manager does not come pre-installed in all Linux distros. As such, you will have to install it by issuing the following command:

sudo apt-get install aptitude
install aptitude
install aptitude

Here is the command-line invocation of aptitude:

aptitude action [arguments...]

For instance, if you want to install python, run the following command:

aptitude install python
Install a specific package version from the repos

If you need to set up a particular version of a package, you can provide the version you would like to target with the “=” sign as shown in the following syntax:

sudo apt install package=version

The version, in this case, must match one of the package version numbers available in the repo. This, therefore, means that utilizing the versioning scheme employed by your distro proves vital.

Reconfigure Packages

Several installable packages include post-installation configuration scripts that are spontaneously executed after the installation is done. These often include prompts for the admin to make configuration choices.

If you need to run via these (and additional) configuration steps later, you can utilize the “dpkg-reconfigure” command. What this command does is look at the package passed to it and re-runs any post-configuration commands included within the package specification:

sudo dpkg-reconfigure package

The above command allows you to access the same and often more prompts you ran upon setup.

Fix broken dependencies and packages

It is sometimes inevitable to ram into packages that may not finish the installation successfully due to dependencies or other related problems. A typical scenario where you might find this case is setting up a .deb package using dpkg, which doesn’t resolve dependencies.

To sort this out, use the following apt command:

sudo apt install -f

The above command will look for any dependencies that aren’t satisfied and try to install them to fix the dependency tree. This should be your first step to resolve cases where your setup process complained about a dependency problem. If you fail to resolve the issue this way and you installed a third-party package, you should strive to remove and replace the package with a newer version that is more actively maintained.

How to remove a Debian package

This section will cover removing the Debian packages from your Debian system. Let us go through the package removal process through each package manager.

Remove package using APT

Removing packages using apt only clears the package data but leaves all the config files behind. If the command is accidentally executed, issue an installation command for the removed package to restore its functionality. Here’s how to remove a package using apt on Debian:

sudo apt-get remove media-types
uninstall media types
uninstall media-types

But if you want to remove the package plus all the configuration files file, then use the purge option is displayed below:

sudo apt-get purge media-types
uninstall media types using purge
uninstall media types using purge

If you ram into a situation where the purge command depicts that the unrequired dependencies are not removed, the -auto-remove option can do the job for you.

sudo apt-get auto-remove media-types
autoremove media-types

On the flip side, you can combine the purge and -auto-remove option to completely do away with all the data and files and unrequired dependencies.

sudo apt-get purge --auto-remove media-types
purge autoremove
purge autoremove
Removing packages using dpkg

The package removal process in dpkg is almost the same. Use “dpkg -r” to do away with the package data. On the other hand, use “dpkg -P” to completely clear the package data from your Debian system. However, you first need to list the package to ensure the correctness of the name as it is installed in the system.

dpkg -l | grep media-types
sudo dpkg -r media-types
sudo dpkg -P media-types

Furthermore, dpkg allows you to forcefully delete the files in a scenario of a distribution upgrade that requires the user to delete or remove a package. The remove option may sometimes not work due to unmet package dependencies or incomplete installation. For such, dpkg offers forced package removal:

sudo dpkg --force-all --remove media-types
Remove packages using aptitude

Removal of packages via aptitude is as straightforward as the setup. You must scroll down and select “Installed Packages” to view all the installed programs. After that, select “net>main” and choose the program to be removed by pressing the “-” key and “g” to remove. The following snapshots show the steps:

step 1
Step 1
Step 2
Step 2
Step 3
Step 3

Clean obsolete package files

It is critical to note that as packages are added and removed from the repos by a distros package maintainers, some packages will become obsolete.

As such, the apt tool can remove any package files on the local system that are linked with packages and are no longer available from the repos using the “autoclean” command.

This is also important to your machine as it frees up the space on your server as well as does away with any potentially outdated packages from your local cache:

sudo apt autoclean

Finding uninstalled Debian package information

All the package management tools know the available packages a user may need to install. The apt-cache is one command that maintains a repo holding information about packages from the source list. It allows the user to get info about the packages in the apt’s cache.

For example, to set up a package relevant to a chatting program with no specific knowledge of the package, a user can utilize this command:

sudo apt-cache search chat
chat relevance
chat relevance

The above command will return a list of packages relevant to a chat app.

Akin, several tools are available to find packages from an already available list of packages. Furthermore, you can find many details about the installed packages with them but not for an already uninstalled one. Use the -d option with an apt-get command for this functionality, as it only downloads the package.

sudo apt-get install -d python3
use d to download
use -d to download

The downloaded package file is located inside /var/cache/apt/archives/ directory. You will now have to use the dpkg command with the -info option to display package details or the -contents to display package files.

dpkg --info /var/cache/apt/archives/nmap_7.60-1ubuntu5_amd64.deb|less

dpkg --contents /var/cache/apt/archives/nmap_7.60-1ubuntu5_amd64.deb|less
 info and contents command
-info and -contents command

Finding installed Debian packages information

The dpkg tool uses many available files in the /var/lib/dpkg directory. One is the /var/lib/dpkg/status file that holds the package status information. The -s option appended to the dpkg command shows the status of the packages on the system.

sudo dpkg -s media-types
installed package info
installed package info

The dpkg also allows users to find details of a specific package and a file belonging to a particular package. The -L option added to the dpkg tool lists all the files and directories of the package of interest. All dpkg needs is a package name; however, when several versions of an app are available, it needs more than a detailed name containing version details.

dpkg -L media-types
when there are multiple names
when there are multiple names

To find a package having a specific file, use the -s flag. In essence, use the subsequent command to determine which package contains the file /usr/bin/apt-get.

dpkg -S /usr/bin/apt-get

commandFinally, we can find details or instead the purpose of a specific package as follows

dpkg -p media-types
find purpose of a particular package
find the purpose of a particular package

Final thoughts

This is a one-stop guide covering every aspect of package management in Debian. The just-concluded article gives a detailed description of Debian’s package management. We discussed several ways to set up, remove, update or upgrade packages. We also discussed finding package status and other details about uninstalled Debian packages. Thank you for reading, and keep following FOSSLinux for more.


Related Articles


Please enter your comment!
Please enter your name here


More Articles Like This