How to List Installed Packages on Ubuntu 20.04 in 2024

As a server administrator, understanding how to list software packages installed in an Ubuntu system is crucial. It is useful for various tasks, such as software inventory tracking, updating, and migrating a hosting environment.

There are several commands for Linux server package management. In addition to having different purposes, these commands vary depending on your operating system version and package manager.

In this article, we will explain how to use commands in Ubuntu to list installed packages. We will explore different methods and command variations for different tasks.

How to List Installed Packages on Ubuntu

Let’s go over the common methods to list installed packages on an Ubuntu 20.04 system. Before proceeding, ensure your virtual private server (VPS) is running the same version or the commands won’t work.

How to List Installed Packages on Ubuntu Using apt

Ubuntu version 14.04 and later comes with the apt package management system. In these versions, you can use the apt command-line utility to list the software packages installed on your system.

Use Terminal to execute the Linux commands in a local system. For a remote machine like a VPS, you must connect via SSH using PuTTY or Terminal.

Hostinger VPS hosting users can obtain the login credentials from the VPS overview’s SSH access tab.

Alternatively, Hostinger users can leverage the Browser terminal for command-line package listing directly through their web browser. Once connected, run the following commands to list packages with apt.

Use the apt list command to show all the available Ubuntu 20.04 packages:

sudo apt list

To list only installed packages, run the apt list command with the –installed option:

sudo apt list –-installed

Add the less argument to show a smaller output. To do so, append a pipe (|) and less at the end of your command:

sudo apt list –-installed | less
Apt command outputting the shortened list of installed packages

While less compresses your output, it will still list all the installed packages. To check if a package is installed, use the grep command with the software name:

sudo apt list --installed | grep packagename

To view more information about a specific package installed on your system, use the apt show command:

sudo apt show packagename

Remember to replace the packagename placeholder with the specific package name. For example, run these commands to list Vim-related packages:

sudo apt list --installed | grep vim

To display detailed information about a particular Vim package, run the following:

sudo apt show vim
The apt show command outputting an information about the vim package

How to Use dpkg-query to List Installed Packages on Ubuntu

For older versions of Ubuntu without the apt package manager, use the dpkg-query command. Dpkg-query usage is similar to apt but doesn’t work with a remote repository.

To list only installed packages with their versions and a brief description, run the following command:

sudo dpkg -l

Use less with the dpkg command to restrict the output like the following:

sudo dpkg -l | less
The dpkg-query command outputting the shortened list of installed packages

Add grep to search for specific packages. Here’s how the command looks:

sudo dpkg -l | grep packageName

Remember to replace packageName with the actual package. For example, enter the following to show installed packages related to PHP:

sudo dpkg -l | grep PHP
The dpkg-query command listing installed PHP-related packages

In addition, you can query information about a specific package using dpkg-query. Here’s the command:

sudo dpkg-query -W packageName

How to Create a List of Installed Packages on Ubuntu

In addition to listing installed software, you may need to save the results for archiving or system configuration replication. Ubuntu lets you use the redirect output symbol (>) to store the installed package names into a file.

To do so, use dpkg-query to request information from the dpkg package manager about the installed applications. Then, add -f ‘${binary:Package}\n’ -W to specify the output format.

End the command with the > symbol to inform where it should store the result, namely the completePackage.txt file. Here’s what the complete command looks like:

sudo dpkg-query -f '${binary:Package}\n' -W > completePackage.txt
The list of installed packages in the complatepackage.txt file

Alternatively, use the –get-selections option to retrieve the packages based on their installation status. Here’s the command:

sudo dpkg --get-selections > completePackage.txt

Creating package lists is also helpful for replicating the installed applications on other machines. To do so, move completePackage.txt to the new system and run this command:

sudo xargs -a completePackage.txt apt install

The xargs command reads the list from the completePackage.txt file. Then, the Linux software installation command adds the same packages to the new system.

You can also use the apt command for package replication on Linux. To list the installed packages in a file, use the command below:

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

After adding the file to another server, install the same packages using the apt-get commands:

sudo apt-get install < completePackage.txt

How to Count the Installed Packages on Ubuntu

You can also count the number of installed Linux packages. The syntax is similar to the one for outputting the list to a file but with a wc or word count command after the pipe.

This command will check the installed packages based on the specified options. In this case, we use the -l option to count the number of lines in your installed package list:

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

Here’s what the output will look like:

dpkg-query outputs the number of installed packages

For counting installed packages, you can also use the wc command with apt:

sudo apt list –-installed | wc -l

How to List Upgradeable Packages

Add the –upgradeable option to your apt command to check the available updates in the repository. Before proceeding, sync the repository using this command:

sudo apt update

Then, run the following command for upgradable package detection:

sudo apt list --upgradeable

Terminal’s output will be similar to this:

The apt command listing all available package updates

How to List All Package Versions

It’s possible to use the Ubuntu apt commands for package version verification. To do so, run the following:

sudo apt list --all-versions
The list of all package versions in Terminal

To query the installed version of a specific package, add its name at the end of the command. See the screenshot below for an example of the command to query PHP:

The apt command lists all installed PHP package version

Users can also list the LOG files within the /var/log/apt directory path to check what packages have been removed, updated, or deleted. To do so, use the less command:

sudo less /var/log/apt/history.log
The package modification history log in Terminal

How to Check Snap and Flatpak Packages

The apt and dpkg-query commands can only list an installed package from their database. To check other packages, like from Linux Snap and Flatpak, change the command accordingly.

For example, use the snap command to list Linux Snap packages installed in your Ubuntu system:

snap list

Similarly, use the following command to check the installed flatpak applications:

flatpak list

Conclusion

Linux users should understand how to use the command line to list installed packages before updating and migrating their machines. To do so in an Ubuntu system, use the apt list and dpkg-query commands via Terminal or SSH client.

Add the standard operator into your command to save the package list into a file in your system. You can also add the wc or word count command to count the installed packages.

In addition, use apt list –upgradable to check the available package updates. If you want to list all package versions, replace the option with –all-versions. Remember to replace apt and dpkg if you use another package manager like Flatpak or Snap.

How to List Installed Packages on Ubuntu FAQ

In this section, we will answer common questions about listing installed packages on an Ubuntu server.

Why List the Installed Packages on Ubuntu?

Users commonly query the installed packages if they want to migrate or replicate a system environment to another machine. In addition, it helps track which packages users must install after formatting their Linux system. 

Can I Use These Methods on Linux Distributions Other Than Ubuntu?

It depends on the distributions. For Debian-based distributions, like Kali Linux, these methods should work. However, for other distributions like CentOS and ArchLinux, you need other commands according to your Linux package management system.

Author
The author

Aris B.

Aris is a Content Writer specializing in Linux and WordPress development. He has a passion for networking, front-end web development, and server administration. By combining his IT and writing experience, Aris creates content that helps people easily understand complex technical topics to start their online journey. Follow him on LinkedIn.