VPS

How to List Installed Packages on Ubuntu 18.04

In Ubuntu, we can install several add-on packages based on our needs. Packages such as Apache, PHP, MySQL, and several others are not pre-loaded with the Operating system. You may also choose to have a certain version installed on your system.

These additional features can be easily installed using the respective packages. There may be certain instances where you would want to replicate the environment from one machine to another. In such cases, you should check the installed packages and their versions.

Similarly, you may want to reinstall the Operating system on your machine which would require you to install the packages again.

To install, uninstall or reinstall packages, as a first step you would always choose first to list the packages. This lets you verify the installed version of the package and cross verify in case a specific package needs to be updated.

Listing of installed packages on Ubuntu can be done in several ways. Over here, we will show you the different ways to do it!

Using APT to List Installed Packages on Ubuntu

Ubuntu uses APT which is a command line tool to help package management. APT was introduced in Ubuntu 14.04. Following this version, the APT command can be used to list the installed packages. The command to list the packages will be:

sudo apt list –-installed

This will show a list of all the installed packages and their versions. The complete list will most likely be very long. In most cases, exceeding your scrollable screen.

You can restrict the output by using less. This will show a smaller output. The command for this will be separated by a pipe (|). An example of this is as shown below:

sudo apt list –-installed | less

While less does compress your output, this will still provide you a list of the installed package. To search for any specific package, you can use grep along with the package listing. With grep, you can search for specific packages.

For instance, if you want to list all the PHP packages which have been installed, then you can use the following command:

sudo apt list –-installed | grep PHP

Similarly, you can search for other specific packages.

Using dpkg-query to List Installed Packages on Ubuntu

In case you have an older version of Ubuntu installed and can’t use the APT tool, use the dpkg-query command. This also lists the installed packages. The basic command would be:

sudo dpkg -l

This output will similarly provide package names and their versions and a brief description of the package.

You can use less along with this command to show a smaller output. The command for this would be:

sudo dpkg -l | less

With grep included in this command, you can search for specific packages. The command would look like this in the command line:

sudo dpkg -l | grep PHP

The above command can be used to check PHP packages.

Create a List of Installed Packages on Ubuntu

There may need to create a complete list of installed packages and have it saved in a file. The below command lets you take the complete output to a file:

sudo dpkg-query -f '${binary:Package}\n' -W > completePackage.txt

Alternatively, you can also try another command:

sudo dpkg --get-selections > completePackage.txt

Over here completePackage.txt is a file which will contain the complete list of installed packages.

While this helps you track the packages installed on your machine, it can also be used to replicate the installation on other machines. You can use this to install the same packages to a new server. To do that, use the following command after placing completePackage.txt into the new machine:

sudo xargs -a completePackage.txt apt install

This can also be done using APT. To get all the installed packages in a file you can use the command shown below:

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

Once we have this in a file, we can install everything on another server using the command:

sudo apt-get install < completePackage.txt

Count the Installed Packages on Ubuntu

You may have a requirement to get a count of the number of installed packages. This can be done similar to the above command by not redirecting the output to a file but by using wc to get the count.

An example of such command is as shown below:

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

The output of this would be the total number of installed packages counted. Similarly, you can use below command with apt to get the total number of installed packages.

sudo apt list –-installed | wc -l

How to List Upgradeable Packages

Using APT you can also check newer package versions which are available for installation. This can be done using the command below:

sudo apt list –upgradeable

List All Versions

In case you have multiple versions installed,  you can view all the versions using APT. This can be done using the below command:

sudo apt list --all-versions

Within /var/log/apt folder, you can view the history.log file to check information about what package has been removed, updated and deleted at what time and which day.

Wrapping Up

You now know all the basic commands to help you see what packages are installed on your Linux Ubuntu 18.04 machine. Manage your server like a pro!

About the author

Edward S.

Edward is Hostinger's copywriter. He's an expert communicator with years of experience in IT as a writer, marketer, and Linux enthusiast. IT is a core pillar of his life, personal and professional. Edward's goal is to encourage millions to achieve an impactful online presence. He also really loves dogs, guitars, and everything related to space.

Add Comment

Click here to post a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get Exclusive Content

Join thousands of webmasters who get our free newsletter with tips on how to drive more traffic and revenue to their websites!

Please wait...

Thank you for sign up!

More in VPS
Bash For Loop Guide and Examples
Close