Table of Contents#
- Prerequisites
- Methods to List Installed Packages
- Filtering and Searching Installed Packages
- Exporting Installed Packages List
- Advanced Tips
- Conclusion
- References
Prerequisites#
Before you begin, ensure you have:
- A running Ubuntu 18.04 LTS system.
- Access to a terminal (open via
Ctrl+Alt+Tor through the applications menu). - Basic familiarity with the command line (optional but helpful).
- Sudo privileges (required only if installing additional tools like
aptitude).
Methods to List Installed Packages#
Ubuntu 18.04 offers multiple tools to list installed packages. Below are the most widely used methods, ranging from low-level to user-friendly.
1. Using dpkg (Low-Level Package Manager)#
dpkg is the low-level package manager for Debian-based systems (including Ubuntu). It directly interacts with .deb packages and maintains a database of installed software. To list all installed packages with dpkg, use:
dpkg -lOutput Explanation:#
The output includes columns like:
Desired=Unknown/Install/Remove/Purge/Hold(e.g.,ifor "install").Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend(e.g.,ifor "installed").Err?=Error/(none)/Reinst-required(usually empty if no errors).Name: Package name.Version: Installed version.Architecture: System architecture (e.g.,amd64).Description: Brief package summary.
Example Output Snippet:
ii accountsservice 0.6.50-0ubuntu1 amd64 query and manipulate user account information
ii acl 2.2.53-6 amd64 Access control list utilities
ii adduser 3.116ubuntu1 all add and remove users and groups
Here, ii in the first two columns indicates the package is desired (i) and installed (i). Other statuses like rc (removed but config files left) or un (uninstalled) may appear for partially removed packages.
2. Using apt (User-Friendly Package Manager)#
apt (Advanced Package Tool) is a higher-level tool that simplifies package management by handling dependencies and repository interactions. It’s the recommended tool for most users on Ubuntu 18.04.
To list all installed packages with apt, run:
apt list --installedKey Features:#
- Color-coded output: Installed packages are marked with
[installed]. - Simplified format: Shows package name, version, and architecture (no status codes like
dpkg).
Example Output Snippet:
accountsservice/bionic-updates,now 0.6.50-0ubuntu1 amd64 [installed]
acl/bionic,now 2.2.53-6 amd64 [installed]
adduser/bionic,now 3.116ubuntu1 all [installed]
Note: To avoid truncation of long package names, use apt list --installed | less to paginate the output.
3. Using aptitude (Advanced Package Manager)#
aptitude is an alternative to apt with more advanced search and filtering capabilities. It’s not pre-installed on Ubuntu 18.04, so install it first:
sudo apt update && sudo apt install aptitudeTo list all installed packages with aptitude, use:
aptitude search '~i'Output Explanation:#
- The
~iflag is anaptitudesearch pattern meaning "installed packages." - Output includes a status code (e.g.,
ifor installed) and package details.
Example Output Snippet:
i accountsservice - query and manipulate user account information
i acl - Access control list utilities
i adduser - add and remove users and groups
aptitude is ideal for complex searches (e.g., filtering by installation date or size).
Filtering and Searching Installed Packages#
Listing all packages is rarely useful. Instead, filter results to find specific packages using tools like grep (for text searching) or built-in flags.
1. Search for a Specific Package#
To check if a package (e.g., nginx) is installed:
With dpkg:#
dpkg -l | grep nginxWith apt:#
apt list --installed | grep nginxWith aptitude:#
aptitude search '~i nginx'Example Output (if nginx is installed):
ii nginx 1.14.0-0ubuntu1.9 amd64 small, powerful, scalable web/proxy server
2. Filter by Package Name Pattern#
Use wildcards (*) to match partial names. For example, list all python-related packages:
dpkg -l 'python*' # With dpkg (quotes avoid shell expansion)
apt list --installed 'python*' # With apt3. List Packages by Installation Size#
To identify large packages (helpful for cleanup), use dpkg-query (a dpkg helper) with formatting:
dpkg-query -W --showformat='${Installed-Size}\t${Package}\n' | sort -nInstalled-Size: Size in kilobytes (KB).sort -n: Sorts numerically (smallest to largest). Add-rto reverse (largest first).
Example Output:
1024 python3-minimal
2048 git
4096 nginx
Exporting Installed Packages List#
Exporting a list of installed packages is useful for backups, system replication, or documentation.
1. Basic List (Package Names Only)#
To save just package names (for reinstalling later), use:
dpkg-query -W -f='${Package}\n' > installed_packages.txtThis generates a text file (installed_packages.txt) with one package name per line.
2. Detailed List (With Versions)#
For a more detailed list (including versions), use:
dpkg -l > installed_packages_detailed.txt3. Reinstall Packages from a List#
To replicate the package list on another Ubuntu 18.04 system, copy installed_packages.txt and run:
sudo xargs apt install -y < installed_packages.txtNote: This may fail if some packages are no longer in repositories. Use apt update first to refresh package lists.
Advanced Tips#
1. List Manually vs. Auto-Installed Packages#
Ubuntu marks packages as "manual" (explicitly installed by the user) or "auto" (installed as dependencies).
-
List manually installed packages:
apt-mark showmanual -
List auto-installed packages:
apt-mark showauto
Use Case: Clean up unused dependencies with sudo apt autoremove (removes unneeded auto-installed packages).
2. Check Package Installation Date#
To find when a package was installed, use dpkg-query with the Installed-Time field (Unix epoch time):
dpkg-query -W -f='${Package}\t${Installed-Time}\n' | grep nginxConvert epoch time to a human-readable date with:
date -d @1620000000 # Replace "1620000000" with the epoch time from the output3. GUI Alternative: Synaptic Package Manager#
If you prefer a graphical interface, install Synaptic:
sudo apt install synapticOpen Synaptic, click Status > Installed to view all installed packages. You can filter, search, and export lists via the GUI.
Conclusion#
Listing installed packages on Ubuntu 18.04 is straightforward with tools like dpkg, apt, and aptitude. Choose dpkg for low-level details, apt for simplicity, and aptitude for advanced searches. Filter results with grep or wildcards, export lists for backups, and use advanced commands to manage dependencies or cleanup.
By mastering these methods, you’ll gain better control over your system’s software and simplify maintenance tasks.