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.


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
APT help will show all the related options that are available to use with apt as shown below.
#sudo apt help
Terminal screenshot displaying apt help command output on Ubuntu for package management options

2.   APT List Package
To list all the installed packages, the command is 
#sudo apt list                  # shows all the installed packages
Terminal screenshot showing the output of apt list package command on Ubuntu for listing installed packages

To check the specific installed package, like Postfix, the command is
#sudo apt list postfix


3.   APT Search Package

If you don’t know about the package description, then use the search option with apt, which will display the complete description of all the components of that package, with the function of each component. As you can the description of postfix below.

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


4.     APT Show Package

This is used to show the package details. Let's look at the details of the postfix package command is 

#sudo apt show postfix

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


This shows the complete information about the Postfix package, like its version, origin, maintainer, task, download size and dependencies.

5.     APT Update 

The basic purpose of the update command is to synchronize the indexes of package files from their sources or repositories before the package installation. Command is 

#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 main difference between update and upgrade is, upgrade is used to install the latest version of software that is currently installed on the local system. It compares the locally installed packages with the updated list of packages from repositories and downloads the new version, then replaces with old one. This upgrades existing packages but doesn’t install packages. To see the upgradeable packages command is

#sudo apt list --upgradable

Terminal screenshot showing apt upgrade command on Ubuntu updating installed packages to the latest versions
This will only list the upgradable packages. If you want to directly upgrade rather than list them command is
#sudo apt upgrade
Terminal screenshot 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 the Apache2 package using the apt command is 

#sudo apt install apache2

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

Here is the package information. It requires dependencies that will be installed with this package. The space required for installation, and then you can proceed by pressing y or n to cancel.


8.  APT Remove Package
Installation and deletion of packages is a major task for a system administrator. To remove the package command is 
#sudo apt remove apache2                                               Terminal screenshot showing apt remove command on Ubuntu removing an installed software package

As with the installation, it has shown the required dependencies to install with the apache2 package. Now, in case of deletion again, it is showing the dependencies to remove with the apache2 package. In summary, it shows the details of installing, removing, not upgrading, and freeing space, and asks to continue pressing y and n for cancel.

9.    APT Full Upgrade

The apt full-upgrade command is used to perform a complete upgrade of all installed packages. It will remove existing packages if necessary to avoid dependency conflicts and upgrade the packages. It downloads and installs all the packages for which updates are available.

#sudo apt full-upgrade

Terminal screenshot displaying apt full-upgrade command on Ubuntu performing complete system upgrade of all packages
Here is the complete detail of what the full upgrade is going to perform.

10.     Add/Remove Repositories

To add the repositories to the system command is 

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

Terminal screenshot showing add-apt-repository command to add or remove software repositories on Ubuntu Linux
Press enter to continue or ctrl-c to cancel. To delete the repository command is 
# sudo add-apt-repository --remove "deb https://dl.winehq.org/wine-builds/ubuntu/ $(lsb_release -cs) main"
Terminal screenshot 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 normally used in Debian-based Linux distributions such as Ubuntu. It is used to install, delete and management of individual .deb packages. It is not capable of managing dependencies automatically or downloading the packages from repositories. Dpkg has limited capabilities as compared to apt; it is not recommended as a primary tool for package installation and management. Here you will learn about some uses of dpkg.

1.    Display dpkg version

Let's see the version of dpkg

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

2.    Dpkg Help

To see the help for the dpkg command is

#sudo dpkg --help

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

3.  Dpkg Install

To install chat-gpt.deb package command is

#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

Displays package status details. If you give the command with the -s option with any package, it will show all the installed packages. To view the status of a specific package, use the -s option followed by the package name. As you can see below

#sudo dpkg -s zstd

Or

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

5.   Dpkg List Files

To list the files that the package own command is

#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

To list all the packages or to list only a specific package, the command is

#sudo dpkg -l zstd

Or

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

7.    Architecture of dpkg installs

To print the architecture of the dpkg install command is

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


8. dpkg unpack a package

To unpack the package command 

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


9.  Reconfigure the Installed Package
To reconfigure the already installed package command is

#sudo dpkg-reconfigure zstd

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

10. Check any issues with the Installed Package
To check any issues with the installed package, the command is
#sudo dpkg --audit zstdUbuntu terminal screenshot showing dpkg --audit command to check and audit broken or partially installed packages

11.   Get Package Selections

To fetch the package name by the selection command is

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

12.    Remove Package

To remove the package command is

#sudo dpkg -r zstd

Ubuntu terminal screenshot showing dpkg --remove command to uninstall a specific Debian package
-r option doesn’t remove the configuration files.

13. Purge Package
To remove the package along with its configuration files. Purge is used
#sudo dpkg -P zstdUbuntu terminal screenshot showing dpkg --purge command to completely remove a Debian package and its configuration files

Conclusion

Dpkg is a low-level package management tool normally used in Debian-based Linux distributions such as Ubuntu. It is used to install, delete and management of individual .deb packages. It is not capable of managing dependencies automatically or downloading the packages from repositories. Dpkg has limited capabilities as compared to apt; it is not recommended as a primary tool for package installation and management. Here you will learn about some uses of dpkg.

Continue to visit seeklinux for more information and updates.

Post a Comment

Previous Post Next Post