Questions

Forum Navigation
Please to create posts and topics.

Linux - List installed package/s and its/their details

A simple question: how to list installed packages and details on a Linux system (Debian/CentOS), using command line?

Debian/Ubuntu

On Debian/Ubuntu based systems we can use dpkg command in the following way:

sudo dpkg -l | more

Or:

sudo dpkg -l | less

If we want to get the description of some specific packages, for example firefox:

sudo dpkg -l | grep firefox

To get the date and time of packages being installed:

cat /var/log/dpkg.log | grep " install "

Another method, always on Debian/Ubuntu systems to list the installed packages is by using apt:

apt list --installed

If you want to display only a list with the packages you have manually installed we could run:

apt --installed list | grep -v automatic

...to not list packages flagged as automatically installed; the -v, --invert-match option invert the sense of matching, to select non-matching lines.

Whereas all versions get listed by:

apt list --all-versions

If we wanto to list all upgradeable OS packages on Debian/Ubuntu:

sudo apt-get update
apt list upgradeable | less

These are very useful commands. For instance if we want to install local installed packages to another computer, you only have to do the following command:

apt list --installed | awk -F/ -v ORS=" " 'NR>1 {print $1}' > apt_packages.txt

In case you only want to get manually installed packages, try this:

apt list --manual-installed | awk -F/ -v ORS=" " 'NR>1 {print $1}' > apt_packages.txt

Now all our apt-packages are ready to install on another or new installed Ubuntu system.

sudo apt-get install < apt_packages.txt

CentOS/RHEL

Show information about all installed packages on CentOS/RHEL, run:

sudo yum list installed

To count all installed packages run:

sudo yum list installed | wc -l

Want to save all installed packages names in a file? Try:

sudo yum list installed > my_list.txt

We can use the grep command as filter too. For example, find out if nginx installed or not:

sudo yum list --installed | grep nginx

If we want to lists extras packages installed on the system that are not available in any known repository:

sudo yum list --extras

To list all packages known to us:

sudo yum list --all

Another way to list packages is by using rpm, that stands for RedHat Package Manager. It comes as standard with most Red-Hat-based Linux operating systems, such as CentOS and Fedora.

To display a list of installed packages, enter the following in a terminal window:

sudo rpm –qa

The –q option means query.
The –a option means all.

To list packages by installation date, enter:

sudo rpm –qa ––last

Search for a package by name using:

sudo rpm –qa | grep –i httpd

This command returns results for the Apache Web Server software.

Output the list of packages to a file by entering the following:

sudo rpm –qa > listed_packages.txt

This command saves a copy of the list in a text file called listed_packages.txt in the current working directory.

Display information about a particular package:

rpm –qi httpd

The –q option stands for query.
The –i option stands for info.

Count the total number of packages installed:

sudo rpm –qa | wc –l

The wc command creates a word count.
The –l option counts the number of lines.

A last quick way to check installed packages is by using yum-utils. We can install yum-utils (CentOS 6.x/7.x) or dnf-utils on a CentOS 8.x:

sudo yum install yum-utils ## centos 6.x/7.x ##
sudo yum install dnf-utils ## centos 8.x ##

So, first, we can list all installed packages with the repoquery command:

sudo yum repoquery –a ––installed
sudo dnf repoquery –a ––installed

The repoquery can use several querytags to retrieve, in a more granular way, the installed packages; here below an example on how to list the available querytags that we can use:

dnf repoquery --querytags
yum repoquery --querytags

Sample outputs:

Available query-tags: use --queryformat ".. %{tag} .."

name, arch, epoch, version, release, reponame (repoid), evr,
debug_name, source_name, source_debug_name,
installtime, buildtime, size, downloadsize, installsize,
provides, requires, obsoletes, conflicts, sourcerpm,
description, summary, license, url

For example, if we want to check when each package has been installed and from which repository we can run a command similar to the following:

repoquery -a --installed --queryformat "%{name}-%{arch}-%{version} installed at '%{installtime}' from '%{reponame}'"

We can list and backup all installed packages using the following syntax:

rpm -qa --qf "%{NAME}\n" | sort > /nas/installed-software-mm-dd-yyyy.log

Use the cat command to review list:

cat /nas/installed-software-mm-dd-yyyy.log

To restore all those packages when needed, run:

yum -y install $(cat /nas/installed-software-mm-dd-yyyy.log)