How to Use APT and DPKG in Ubuntu: A Complete Package Management Guide

 

SeekLinux tutorial banner showing APT and DPKG package management commands on Ubuntu terminal

Introduction
Every Linux distribution has its own set of package management tools that come by default with these distributions. They utilize various package formats and tools to manage these packages.


Red Hat Enterprise Linux uses the RPM package format and utilizes RPM and YUM for package management. Ubuntu is a Debian-based Linux distribution and is freely available for use, with a comprehensive package management system. Ubuntu utilizes the .deb packaging format and tools for package management, such as apt and dpkg.


In this guide, you will learn about the Ubuntu package management tools, a fundamental feature of the Ubuntu system administration. You will learn how to use apt in Ubuntu for managing packages, updating your system and installing software from repositories. You will also learn how the dpkg command in Ubuntu helps you manually install and manage .deb files. This will serve as a quick reference for when you learn how to perform package management tasks in these systems.


Package Management Tools
Ubuntu uses apt and dpkg as package management tools to install, delete, update, upgrade and manage the packages. Both tools have their own way of handling packages; let's see the detailed working of these tools.


Before learning how to use the APT and DPKG in the Ubuntu, it is helpful to understand the fundamentals of the Linux operating system. you are new to the Linux, read our beginner guide on What is Linux? An Introduction to Linux and Its Popular Distributions.


APT (Advanced Package Tool)

is a standard command-line tool in Debian-based Linux distributions used for installing, deleting, updating, and upgrading software packages and system-related components. APT interacts with software repositories to download the packages and install them on the system, automatically manages dependencies and ensures system stability. This guide will help the system administrators understand the Ubuntu package installation using APT and tracking of updates and upgrades of installed packages.


1.  APT Help
The apt help command displays the available options and usage information for the APT tool.

sudo apt help
Terminal displaying apt help command output on Ubuntu for package management options

2.   APT List Package
To list all installed packages, use the following command: 

sudo apt list                  # shows all the installed packages
Terminal showing the output of apt list package command on Ubuntu for listing installed packages

To verify whether a specific package, such as postfix is installed, use the following command:

sudo apt list postfix


3.   APT Search Package

If you are unsure about a package or want to explore available options then you can use the search feature in APT. It displays matching packages along with a brief description of each. As you can the description of postfix below.


sudo apt search postfix                                         Terminal displaying the output of apt search package command on Ubuntu for finding software packages


4.     APT Show Package

The apt show command displays detailed information about a specific package including its version, dependencies, maintainer and description. 


sudo apt show postfix

Terminal showing output of apt show command on Ubuntu displaying detailed package information


The output provides comprehensive details about the postfix package such as version, origin, maintainer, download size and dependency information.

The Package management in Linux is usually performed through the terminal. you are new to working with the Linux commands, check our tutorial on 10 Linux Basic Commands Every Beginner Should Know.

5.     APT Update 

The apt update command refreshes the information of package index by synchronizing from configured repositories. It ensures your system has the latest details about available packages before installation or upgrade.


sudo apt update

Terminal window running sudo apt update command on Ubuntu system
It refreshes the repositories and fetches the current information.

6.      APT Upgrade

The apt upgrade command installs the latest version of packages that are already installed on the system. It makes comparison of installed packages with the updated package index and upgrades them if newer versions are available. This command upgrades existing packages but does not install new ones or remove existing packages.


To view the list of upgradable packages, use the following command:


sudo apt list --upgradable

Terminal showing apt upgrade command on Ubuntu updating installed packages to the latest versions

This command lists all upgradable packages. To upgrade them directly, use the following command:

sudo apt upgrade
Terminal showing apt upgrade command on Ubuntu updating installed packages to the latest versions

If you want to upgrade, Press y and press no to cancel.

7.     APT Install

To install a package such as apache2, use the following command: 


sudo apt install apache2

Example of sudo apt install package-name command in Ubuntu for software installation

The installation process shows package information such as dependencies and required disk space. You can confirm the installation by pressing y or cancel it by pressing n.


When installing the software packages, files are placed in the different directories within the Linux filesystem. The filesystem structure will help you to manage the installed software more effectively. Read our guide on Linux Directory Structure and File System – Beginners to Pro Guide.


8.  APT Remove Package
The apt remove command is used to uninstall a package while keeping its configuration files. For example: 

sudo apt remove apache2                                               Terminal showing apt remove command on Ubuntu removing an installed software package

During package removal the system shows information about related dependencies and the disk space that will be freed. You can proceed by pressing y or cancel the operation by pressing n.

9.    APT Full Upgrade

The apt full upgrade command upgrades all installed packages and automatically manages dependencies. It may remove existing packages or install new ones if necessary to complete the upgrade.


sudo apt full-upgrade

Terminal displaying apt full-upgrade command on Ubuntu performing complete system upgrade of all packages

This is the complete detail of what the full upgrade is going to perform.

10.     Add/Remove Repositories

To add a repository to the system, use the following command:


sudo add-apt-repository "deb https://dl.winehq.org/wine-builds/ubuntu/ $(lsb_release -cs) main"

Terminal showing add-apt-repository command to add or remove software repositories on Ubuntu Linux

Press enter to continue or Ctrl+c to cancel the operation. To remove a repository, use the following command:

sudo add-apt-repository --remove "deb https://dl.winehq.org/wine-builds/ubuntu/ $(lsb_release -cs) main"
Terminal showing command to remove a software repository using add-apt-repository --remove on Ubuntu Linux

DPKG (Debian Package)

Dpkg is a low-level package management tool used in Debian based Linux distributions such as Ubuntu. It is used to install, remove and manage individual .deb packages.


Unlike APT dpkg does not handle dependencies automatically or download packages from repositories. Due to its limited functionality, it is typically not used as the primary tool for package management.


Different Linux distributions use the different package management systems. For example, Red Hat based systems use the RPM and YUM or DNF. You can read this in our guide on RHEL 9 Package Management Guide: How to Install, Update & Remove Packages.

1.    Display dpkg version

To check the installed version of dpkg, use the following command:


sudo dpkg --version                                                      Terminal displaying the dpkg --version command output on Ubuntu Linux

2.    Dpkg Help

To view help information for the dpkg command, use the following:


sudo dpkg --help

for the available options and switches to use for package management.         Ubuntu terminal displaying dpkg --help command output with available options

3.  Dpkg Install

To install a .deb package for example, chat-gpt.deb, use the following command:


sudo dpkg -i ChatGPT_1.1.0_linux_x86_64.deb        ## or


sudo dpkg --install  ChatGPT_1.1.0_linux_x86_64.deb                                 Ubuntu terminal using dpkg -i to install a local Debian package file

4.   Dpkg Status

The dpkg -s command displays detailed status information about a specific package including its installation status, version and dependencies.


#sudo dpkg -s zstd

Or


sudo dpkg --status zstd                                                      Ubuntu terminal showing the dpkg -s command to check installed package status

5.   Dpkg List Files

To list the files owned by a package, use the following command:


#sudo dpkg -L zstd

Or


sudo dpkg --listfiles zstd

List of installed packages displayed using dpkg -l command on Linux

Files related to the zstd package.

6.    dpkg List Packages Concisely

The dpkg -l command lists all installed packages. You can also specify a package name to display details for a particular package.


#sudo dpkg -l zstd

Or


sudo dpkg --list zstd                                    Ubuntu terminal showing dpkg --get-selections command output listing all installed packages

7.    Architecture of dpkg installs

The dpkg --print-architecture command shows the system’s architecture such as amd64 or arm64.


sudo dpkg --print-architecture                                  Ubuntu terminal showing dpkg --print-architecture command displaying the system architecture type


8. dpkg unpack a package

The dpkg --unpack command extracts the contents of a .deb package without installing it. This step prepares only the package files but it does not configure or complete the installation.

sudo dpkg --unpack flashplugin-installer_11.2.202.350ubuntu1_amd64.deb                    Ubuntu terminal displaying dpkg --unpack command used to unpack Debian package files without installing them


9.  Reconfigure the Installed Package
The dpkg-reconfigure command allows you to reconfigure an installed package by rerunning its configuration process.


sudo dpkg-reconfigure zstd

Ubuntu terminal showing dpkg-reconfigure command used to reconfigure an installed Debian package

10. Check any issues with the Installed Package
The dpkg --audit command identifies partially installed or broken packages that requires attention.

sudo dpkg --audit zstdUbuntu terminal showing dpkg --audit command to check and audit broken or partially installed packages

11.   Get Package Selections

The dpkg --get-selections command lists all installed packages along with their installation status.

sudo dpkg --get-selections                           Ubuntu terminal showing dpkg --get-selections command to list and select installed packages

12.    Remove Package

To remove a package, use the following command:


sudo dpkg -r zstd

Ubuntu terminal showing dpkg --remove command to uninstall a specific Debian package

The -r option removes the package  only but retains its configuration files.

13. Purge Package
To remove a package along with its configuration files, use the following command:

sudo dpkg -P zstdUbuntu terminal showing dpkg --purge command to completely remove a Debian package and its configuration files

Audit Broken Packages

dpkg --audit
Ubuntu terminal running dpkg --audit to identify broken or partially installed packages

Running sudo dpkg --audit identifies the partially installed or unpacked packages. This issue typically occurs when a previous installation or upgrade fails or when dependencies are not properly installed.

Follow the steps below to resolve the issue:

Configure the unpacked packages
Use the dpkg --configure command to complete the configuration of partially installed packages:

sudo dpkg --configure flashplugin-installer man-db update-notifier-common
Terminal command dpkg --configure used to complete configuration of unpacked packages in Linux

This command attempts to complete the configuration of partially installed packages.
Failure of a package generates an error message in the system with cause like missing dependencies or broken scripts.

Fix broken dependencies automatically

sudo apt --fix-broken install
Ubuntu terminal running sudo apt --fix-broken install to fix broken dependencies and repair partially installed packages

This command installs missing dependencies and resolves conflicts of packages. It can be safely executed even when packages are partially installed.

Verify package status
To verify that all packages are correctly installed and configured, use the following command:

sudo dpkg --audit
Ubuntu terminal running sudo dpkg --audit to detect broken or partially installed packages

This command should show no packages needing configuration.

Quick Summary Command Sequence
  • sudo dpkg --configure flashplugin-installer man-db update-notifier-common
  • sudo apt --fix-broken install
  • sudo dpkg --audit
After this, your system should be clean, with no partially installed packages.

Common APT and GPKG Commands

The following table summarizes the most commonly used APT and DPKG commands for package management in Ubuntu.

APT Commands

Command Purpose Example
apt help Display help and options sudo apt help
apt list List installed packages sudo apt list
apt search Search for packages sudo apt search postfix
apt show Show package details sudo apt show postfix
apt update Update package index sudo apt update
apt upgrade Upgrade installed packages sudo apt upgrade
apt full-upgrade Perform full system upgrade sudo apt full-upgrade
apt install Install a package sudo apt install apache2
apt remove Remove a package sudo apt remove apache2
add-apt-repository Add or remove repositories sudo add-apt-repository repo

DPKG Commands

Command Purpose Example
dpkg --version Display dpkg version dpkg --version
dpkg --help Show help information dpkg --help
dpkg -i Install .deb package sudo dpkg -i package.deb
dpkg -s Check package status sudo dpkg -s zstd
dpkg -L List files of a package sudo dpkg -L zstd
dpkg -l List installed packages sudo dpkg -l
dpkg --print-architecture Show system architecture dpkg --print-architecture
dpkg --unpack Unpack a package sudo dpkg --unpack package.deb
dpkg-reconfigure Reconfigure a package sudo dpkg-reconfigure zstd
dpkg --audit Check broken packages sudo dpkg --audit
dpkg --get-selections List package selections sudo dpkg --get-selections
dpkg -r Remove package (keep config) sudo dpkg -r zstd
dpkg -P Remove package with config sudo dpkg -P zstd

Best Practices for Ubuntu Package Management
  •  Always run sudo apt update before installing
  • Prefer apt over dpkg for automatic dependency handling
  • Use dpkg only for local .deb files
  • Regularly run sudo apt autoremove to clean unused packages
  • Enable automatic security updates on production systems

The Software management is one of the core responsibilities of a Linux system administrator. Learn more about managing the user access and permissions in our tutorial on Managing Users and Groups in Linux – A Complete Guide for Beginners.

Frequently Asked Questions (FAQs)

Q1: What’s the difference between apt and apt-get?
A: apt is a more user-friendly, newer command with progress bars and sensible defaults. Apt-get is older but still supported.

Q2: Can I use dpkg instead of apt?
A: Yes, but dpkg doesn’t resolve dependencies. Use apt when possible.

Q3: How do I fix a broken package installation?
A: Run sudo apt --fix-broken install.

Q4: Is it safe to remove packages with autoremove?
A: Usually yes, but always review the list before confirming.

Conclusion

Ubuntu package management using APT and DPKG provides powerful tools for installing, updating, and maintaining software. As APT simplifies dependency management and system updates, DPKG offers low-level control for handling individual packages.

By understanding and using these tools effectively, administrators can maintain a stable, secure, and well-managed Linuxsystem.

Continue to visit seeklinux for more information and updates.

Author: Aqeel Anwar


SeekLinux Author
SeekLinux Team
Linux Engineers | DevOps | Security Enthusiasts

SeekLinux Team shares practical Linux tutorials, SSL/TLS certificate guides, commands and DevOps solutions. Our goal is to simplify system administration and help you master real-world server and security tasks.

Learn more about us →

Post a Comment

Previous Post Next Post