Knowing the installed packages on your Ubuntu system is crucial for several reasons. You may need to replicate your environment from one machine to another or reinstall Ubuntu on the same machine. Having a list of installed packages will help ensure you know what applications and libraries are present and can reinstall them if needed.
When installing, upgrading, downgrading, or removing packages, listing installed packages allows you to verify version numbers and dependencies. Overall, being able to view installed packages gives you greater control and understanding of your Ubuntu system.
In this comprehensive guide, we will cover several methods for listing installed packages on Ubuntu:
Using the apt Command
The Advanced Packaging Tool (apt) is the default package management utility included in Ubuntu. It was first introduced in Ubuntu 14.04 and consolidated the most commonly used functions of apt-get and apt-cache into one program.
To list all installed packages with apt, run:
sudo apt list --installed
This will display all user-installed applications along with many libraries and dependencies in the background that apt handles automatically.
Here is a snippet of the output:
The list shows the package name, version, architecture, and a description for each installed package.
To paginate the long output, you can pipe to the less program:
sudo apt list --installed | less
This will display the results one page at a time, allowing you to scroll through the full list.
To check if a specific package like Firefox is installed, you can combine apt with grep:
sudo apt list --installed | grep firefox
This will filter the installed package list and only display lines containing "firefox" to confirm it is present on the system.
Using dpkg Package Manager
The dpkg package manager provides the core functionality in Debian-based distros like Ubuntu for installing, removing, and inspecting packages. The dpkg-query
command allows querying the local dpkg database for useful package details.
To list all packages installed on the system with dpkg, use:
dpkg-query -l
Here is a small snippet showing some of the columns included:
We can again pipe the output to less to paginate it:
dpkg-query -l | less
And search for a specific package like nginx with grep:
dpkg-query -l | grep nginx
This verifies nginx is installed and displays the relevant info line containing it.
Exporting a Package List to a File
You may want to get the list of installed packages from a system and export it to a file for analysis or tracking purposes.
dpkg provides a way to output just the package names to a text file like this:
dpkg-query -f ‘${Package}\n‘ -W > packages.txt
Let‘s break this down:
-f ‘${Package}\n‘
– formats the output to only show package name and a new line-W
– tells dpkg to only output package names, no other metadata>
– redirect symbol to save output to a filepackages.txt
– filename to write output to
Now packages.txt will contain a list of all packages line-by-line.
To view the file contents, use cat:
cat packages.txt
You now have a file containing just the installed package names that can be easily inspected, shared, analyzed, or compared against other systems.
Listing Package Info with apt-mark
The apt suite of tools contains apt-mark
which provides a simple way to query additional info about installed packages.
To list all packages installed automatically as dependencies, use:
apt-mark showauto
This can help identify packages you didn‘t directly install yourself.
To list packages installed manually, use:
apt-mark showmanual
This will display just the software you intentionally installed with apt.
And you can view packages that are no longer required by checking orphaned packages:
apt-mark showorphans
This helps highlight unused packages for potential removal to save disk space.
Analyzing Disk Space Usage
To understand the disk space used by installed packages, you can use the ncdu
utility to analyze usage and see a breakdown of which packages are utilizing the most space.
Install it with:
sudo apt install ncdu
Then run it to inspect disk usage:
sudo ncdu /
This will display an interactive ncurses-based chart showing usage by directory. You can navigate the chart and dig down into categories to understand what packages and files are using space on the root drive.
For even more powerful analysis, there are tools like Baobab that provide graphical disk usage breakdowns.
Listing Package Info with dpkg-query
The dpkg-query command has many options for querying useful package details beyond just listing installed packages.
To show packages that list Firefox as a dependency, use:
dpkg-query -Wf ‘${db:Status-Abbrev} ${Package} firefox\n‘
This will display all packages that have firefox tagged as a dependency in the status field.
You can also pass a package name to get info on just a specific package, like to get the installation date:
dpkg-query -W -f=‘${Installed-Date} ${Package}\n‘ firefox
And to get the installation size of a package:
dpkg-query -W -f=‘${Package} ${Installed-Size}\n‘ firefox
These are just a few examples of the useful info dpkg-query can provide on installed packages. See man dpkg-query
for additional formatting options.
Listing Packages with Aptitude
Aptitude is another popular frontend for managing Debian/Ubuntu packages. It provides enhanced search capabilities and formatting options when querying packages.
To list all installed packages with Aptitude, use:
aptitude search ‘~i‘
This leverages the powerful aptitude search syntax to match on installed packages specifically.
To get a summary view of all packages grouped by state, use:
aptitude search ‘~i‘ -F ‘%p %d %s %V %v %S‘
This custom output formatting shows the package name, description, state label, version, vendor, and package size.
Aptitude makes it easier to search and filter on specific package properties when analyzing what‘s installed on a system.
Conclusion
Having visibility into installed packages is critical for managing Ubuntu servers and desktops. This guide covered the main tools and techniques for listing package details, including apt, dpkg, apt-mark, aptitude, and analyzing disk usage.
Some key takeaways:
- The
apt list --installed
command shows all user and auto-installed packages dpkg-query -l
provides low-level package listing from the dpkg database- Output can be saved to a file for tracking or comparison
- Related utilities like apt-mark and aptitude offer additional reporting
- Disk usage analyzers like ncdu and Baobab identify space consumption
Practice using these tools on your own Ubuntu systems to better understand what packages are present and how they impact resource usage. Mastering package management leads to easier system administration.