Introduction
Having a list of installed packages helps system administrators maintain, replicate, and reinstall systems. Linux based systems install dependencies all the time, hence it is essential to know what is on the system.
In this tutorial, learn how to list all installed packages with apt and dpkg, save the list to a file or list specific packages and versions.
Prerequisites
- A Debian-based distribution such as Ubuntu
- A command line/terminal window (Ctrl+Alt+T)
- The apt package manager, included by default
Using Apt to List Installed Packages
Starting with version 14.04, Ubuntu comes pre-equipped with the apt package manager. Besides helping you install packages, apt makes listing installed packages easy.
Start by opening the terminal. To generate a list of all installed packages:
sudo apt list --installed
Upon executing, the output will display all installed software packages, including versions and architecture. It will also list all packages installed as dependencies.
The image below is the type of output you can expect to see.
For most users, the list will be a long one. Try piping the output using less
.
sudo apt list --installed | less
The output will be an easily manageable list of installed software packages. Use the up and down arrow keys to scroll up and down.
To reactivate the command line, press Q.
How to List Specific Package
To get a list of a specific software package and its respective details, type the following in the terminal:
sudo apt list --installed | grep -i package_name
Instead of package_name
, type the name of the software package you want to look up.
Use the apt show
command to view details of a specific installed package.
sudo apt show package_name
How to List Upgradable Packages
To check which packages may be updated, use the apt list
command with the upgradable
flag. Pipe the command with less
for easy navigation.
apt list –upgradable | less
Once the system executes the command, the output will display all upgradable packages. Furthermore, it will display details, such as the installed version and the latest version available.
If using less
, press Q to return to the command line.
List All Versions
To list all versions of a package, execute the following command:
apt-cache policy Package_Name
The system will present all the available package versions in a repository. This is a repository-wide search. You will get results even for packages that have not been installed on your system.
Let us consider the sample output below.
Installed indicates the version installed on the system. If you don’t have any version installed, the output will display none.
Candidate indicates the latest version available. In our example, we can update the udev package to version 237-3ubuntu10.21.
Version Table indicates which versions are available and in which repository.
Using dpkg to List Installed Packages on Ubuntu
Systems running older versions of Ubuntu might not have the apt tool. However, an alternative solution is to use dpkg
commands.
Open your terminal window and type:
dpkg-query -l
You do not need to run these commands as a superuser. Hence, there is no need to invoke sudo
. Both apt and apt-get use dpkg commands so this is a viable method even on the latest versions of Ubuntu.
The output should display details such as package name, version, architecture, and a short description. The image below represents the type of output you can expect.
As with apt, you can pipe the results with less
to generate a smaller and more manageable output.
dpkg-query –l | less
You can also use the grep command to filter out a specific package.
sudo dpkg -l | grep -i package_name
Instead of package_name, type the name of a specific software package.
Create a List of Installed Packages
Having a list of all installed packages is helpful when you want to create identical systems.
To export the list and save it to a file, run the command:
dpkg-query -f '${binary:Package}/n' -W > packages_list.txt
Note: all_packages_list.txt is the name of the saved file. You can define any file name you opt for, as long as you retain the .txt file extension.
Count Installed Packages
The total number of installed packages is another useful piece of information.
To view the total number of installed packages, use the following command:
dpkg-query -f '${binary:Package}/n' -W | wc –l
This command lists all installed packages and then the wc
utility counts the lines. As you can see, we have 508 installed packages on our machine.
List Snap Packages
All of the above options will display packages installed with the apt and dpkg package managers. However, Snap packages are not available with the commands mentioned above.
To get a list of all Snaps installed on Ubuntu, type:
snap list
See example output below.
Note: Learn about the differences between Snap packaging system and the APT package manager in Snap vs Apt.
Conclusion
By following this guide, you should have learned how to list installed packages on Ubuntu and other Debian-based systems. If there is a problem with the installed packages, read our article how to fix broken packages in Ubuntu.
The instructions provide answers to filtering specific installed packages, counting all installed packages, and listing upgradeable packages. Now you can move on to learning how to list information about directories and files with 19 Crucial Linux ls Commands.
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/223942.html