How can I see DPKG and apt history

10

This tutorial explains how to see dpkg and apt history in Debian-based Linux distributions.

After reading this tutorial, you will know how to find information about installed, removed, and upgraded packages using commands apt, dpkg-query, and reading dpkg logs. There are instructions to create a list of installed packages, install all listed packages on a new computer, and additional apt and dpkg tips.

See installed packages using apt

The command below prints a list of all software installed through the apt/apt-get packages manager.

Listing installed packages with dpkg-query

dpkg-query is a command to display information on packages from the dpkg database.

How can I see DPKG and apt history How can I see DPKG and apt history 1625628716 70 How can I see DPKG and apt history

Count all installed packages

Using dpkg-query, you can get a total count of all installed packages. The -f flag will list all binary packages only, then the wc command counts all listed packages:

sudo dpkg-query -f ‘${binary:Package}n’ -W | wc -l

How can I see DPKG and apt history How can I see DPKG and apt history 1625628717 130 How can I see DPKG and apt history

As you can see, there are 2802 installed packages. 

See installed packages reading logs

You can read recent apt activity (installation, removal, upgrade) by reading the log /var/log/apt/history.log as shown below:

cat /var/log/apt/history.log

How can I see DPKG and apt history How can I see DPKG and apt history 1625628718 366 How can I see DPKG and apt history

To get information on packages installed using dpkg, you need to read dpkg logs located at /var/log. You can read the current log by running the command below:

grep ” install ” /var/log/dpkg.log

How can I see DPKG and apt history How can I see DPKG and apt history 1625628719 250 How can I see DPKG and apt history

To check the previous log,  see the file /var/log/dpkg.log.1.

grep ” install ” /var/log/dpkg.log.1

How can I see DPKG and apt history How can I see DPKG and apt history 1625628720 118 How can I see DPKG and apt history

Reading compressed logs is the same process but with zgrep instead of grep, as shown in the example below.

zgrep ” install ” /var/log/dpkg.log.10.gz

How can I see DPKG and apt history How can I see DPKG and apt history 1625628720 97 How can I see DPKG and apt history

If you want to see all compressed logs at once, you can use a wildcard like in the following example:

zgrep ” install ” /var/log/dpkg.log.*.gz

How can I see DPKG and apt history How can I see DPKG and apt history 1625628721 406 How can I see DPKG and apt history

List removed packages

You also can list removed packages by reading logs by replacing “ install” with “remove”, as shown in the image below.

grep “remove ” /var/log/dpkg.log

How can I see DPKG and apt history How can I see DPKG and apt history 1625628722 895 How can I see DPKG and apt history

As with the previous example, you can also use the zgrep command and a wildcard to read all compressed logs, as shown in the screenshot below.

zgrep “remove ” /var/log/dpkg.log.*.gz

How can I see DPKG and apt history How can I see DPKG and apt history 1625628723 759 How can I see DPKG and apt history

List upgraded packages

To show upgraded packages replace “install” or “remove “ with “upgrade”, as shown in the example below.

grep “upgrade ” /var/log/dpkg.log

How can I see DPKG and apt history How can I see DPKG and apt history 1625628724 418 How can I see DPKG and apt history

Use zgrep to read compressed logs.

zgrep “upgrade ” /var/log/dpkg.log.10.gz

How can I see DPKG and apt history How can I see DPKG and apt history 1625628724 914 How can I see DPKG and apt history

As with previous examples, you also can use a wildcard.

zgrep “upgrade ” /var/log/dpkg.log.*.gz

How can I see DPKG and apt history How can I see DPKG and apt history 1625628726 393 How can I see DPKG and apt history

Export list of installed packages to install on a new device

You can create a list of installed packages, then import it to a new device to install the same software.

To create a list of installed packages, you can do a similar procedure as the one used to count installed packages, as shown below. Instead of counting, the following command creates a list called installedpackages.

sudo dpkg-query -f ‘${binary:Package}n’ -W > installedpackages

How can I see DPKG and apt history How can I see DPKG and apt history 1625628726 408 How can I see DPKG and apt history

On the computer you want to install the same packages run:

sudo xargs -a installedpackages apt install

How can I see DPKG and apt history How can I see DPKG and apt history 1625628727 751 How can I see DPKG and apt history

In the screenshot below, the apt was executed on the same computer the list was created; thus, it detected packages are already installed.

Updating outdated packages

You can use the command apt to check for outdated packages to update by running the command below:

sudo apt –fix-missing update

How can I see DPKG and apt history How can I see DPKG and apt history 1625628729 791 How can I see DPKG and apt history

Fixing dependencies or broken packages

To fix dependencies or broken packages, after running apt-get update, execute the command below.

How can I see DPKG and apt history How can I see DPKG and apt history 1625628730 719 How can I see DPKG and apt history

About apt and dpkg

  • APT (Advanced Package Tool) automates packages retrieval, configuration (including dependency resolution), and installation. It can be considered the main packages manager in some Debian-based Linux distributions (including Debian itself) or a front-end for the dpkg packages manager.
    The main advantage of APT over DPKG is its ability to resolve dependencies and track updates. Apt is also used for package removal, updates, and this tutorial to retrieve information.
  • DPKG is the Debian package manager used by APT. As said previously, while it is a lot better than compilating, it has disadvantages before APT. It handles individual packages and doesn’t resolve dependencies. Still, DPKG includes interesting tools like the dpkg-query mentioned in this tutorial. Other tools include dpkg-split, dpkg-statoverride, dpkg-trigger, dpkg-divert. Dpkg include the following development tools: dpkg-source, dpkg-gencontrol, dpkg-shlibdeps, dpkg-genchanges, dpkg-buildpackage, dpkg-dist and dpkg-parsechangelog.

For additional information on the apt/apt-get packages manager, visit the man page https://linux.die.net/man/8/apt-get.

For additional information on dpkg, visit the man page https://linux.die.net/man/1/dpkg.

Conclusion

As you can see, showing installed, removed and upgraded software is an easy task any Linux user level can execute with a few commands. Linux offers a variety of versatile commands and tools to manage and administrate packages in a custom way. For example, getting the total count of installed programs in Microsoft Windows may be harder or impossible without the help of an external tool.

Learning simple tasks like the explained in this tutorial may save you a lot of time, as proven in the section describing how to export a list of packages to install on a new device, especially useful when you need to create a similar serverand cloning isn’t an option.

Learning to administer and manage packages is key and basic knowledge any user must-have.

I hope this tutorial was useful. Keep following Linux Hint for more Linux tips and tutorials.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More