How to Check Installed Packages on Ubuntu: A Complete Guide for Beginners and Intermediate Users

目次

1. Introduction

Ubuntu is a reliable Linux distribution trusted by many developers and engineers. While using it, you may sometimes need to check which packages are currently installed on your system.

For example, you might want to verify whether a specific package is installed correctly or identify and remove unnecessary packages. In such cases, knowing how to view installed packages becomes essential.

This article explains in detail how to check installed packages in Ubuntu. We will introduce practical methods suitable for beginners to intermediate users, so read to the end to master these essential commands.

2. How to List Installed Packages

There are several ways to check installed packages on Ubuntu. Here, we’ll introduce the three most common methods, each suitable for different preferences and use cases.

Using the apt Command

The apt command is one of the most frequently used package management tools in Ubuntu. To list installed packages, run the following command:

apt list --installed

Command Explanation

  • apt list: Lists package information available in the system.
  • --installed: Displays only the packages that are currently installed.

Example Output

When executed, you will see a list of installed packages similar to the example below:

accountsservice/now 0.6.55-0ubuntu12 amd64 [installed,automatic]
acl/now 2.2.53-10 amd64 [installed]

Using the dpkg Command

dpkg is a low-level tool used to manage Debian packages directly. You can use the following command to view installed packages:

dpkg-query -l

Command Explanation

  • dpkg-query: Queries the dpkg database to retrieve package information.
  • -l: Lists all installed packages.

Example Output

ii  accountsservice   0.6.55-0ubuntu12   amd64   query and manipulate user account information
ii  acl               2.2.53-10          amd64   access control list utilities

Here, ii indicates that the package is correctly installed.

Using the snap Command

snap is a modern package management system introduced in Ubuntu. To check Snap-installed packages, use the following command:

snap list

Command Explanation

  • snap list: Displays a list of all Snap packages installed on the system.

Example Output

Name     Version    Rev   Tracking       Publisher     Notes
core     16-2.58    12834 latest/stable  canonical✓    core

This command is useful for checking the version and revision details of Snap packages.

Summary

  • apt list --installed: Simple and quick way to view installed packages.
  • dpkg-query -l: Suitable for checking more detailed information.
  • snap list: For viewing Snap-installed packages.

By using these commands appropriately, you can efficiently manage Ubuntu packages.

3. How to Check if a Specific Package Is Installed

Ubuntu provides several efficient methods to check whether a specific package is installed. Let’s explore how to do this using the apt and dpkg commands.

Checking with the apt Command

With the apt command, you can easily search for a specific package in the list of installed packages.

Command Example

Combine it with grep to search for a specific package name:

apt list --installed | grep package-name

Example Execution

To check if the curl package is installed:

apt list --installed | grep curl

Example Output

curl/now 7.68.0-1ubuntu2.6 amd64 [installed]

This confirms that curl is installed on the system.

Checking with the dpkg Command

The dpkg command can also be used to verify whether a particular package is installed.

Command Example

dpkg-query -l | grep package-name

Example Execution

For example, to check if git is installed:

dpkg-query -l | grep git

Example Output

ii  git    1:2.25.1-1ubuntu3.2 amd64 fast, scalable, distributed revision control system

The ii status means the package is properly installed.

Checking Snap Packages

If the package was installed via Snap, use the following command:

snap list | grep package-name

Example Execution

To check if chromium is installed as a Snap package:

snap list | grep chromium

Example Output

chromium    97.0.4692.99    1892   latest/stable    canonical✓    -

This confirms that chromium is installed as a Snap package.

Summary

  • apt list --installed | grep package-name: Simple and quick check.
  • dpkg-query -l | grep package-name: More detailed information.
  • snap list | grep package-name: For Snap packages specifically.

Using these methods, you can quickly verify whether a particular package is installed on your system.

4. How to Display Detailed Information About Installed Packages

Sometimes, you may want to check detailed information about an installed package—such as its function, dependencies, or version. In Ubuntu, you can use the following commands to retrieve such details.

Using the apt show Command

The apt show command displays detailed information about a specific package.

Command Example

apt show package-name

Example Execution

For example, to view detailed information about the curl package:

apt show curl

Example Output

Package: curl
Version: 7.68.0-1ubuntu2.6
Priority: optional
Section: web
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Description: command line tool for transferring data with URL syntax
 This is a command line tool and library for transferring data with URLs.

Key Information

  • Package: Name of the package.
  • Version: The version number of the package.
  • Section: The category it belongs to (e.g., web, utils).
  • Maintainer: Contact information for the package maintainer.
  • Description: Overview of what the package does.

Using the dpkg Command

You can also use the dpkg command to view details about a specific package.

Command Example

dpkg -s package-name

Example Execution

For example, to view details about the git package:

dpkg -s git

Example Output

Package: git
Status: install ok installed
Priority: optional
Section: vcs
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Description: fast, scalable, distributed revision control system
 Git is a fast, scalable, distributed revision control system with an
 unusually rich command set that provides both high-level operations
 and full access to internals.

This command provides the installation status and summary of the package.

Checking Dependencies

If you want to check dependencies, apt show is also useful. For example, to view dependencies for the curl package:

apt show curl

The output includes dependency information such as:

Depends: libc6 (>= 2.17), libcurl4 (>= 7.68.0-1ubuntu2.6)

This helps identify which other packages are required for the software to function correctly.

Summary

  • apt show package-name: Ideal for checking dependencies and detailed package info.
  • dpkg -s package-name: Useful for quick and concise information.

These commands are valuable for understanding packages in detail and can assist in system maintenance and troubleshooting.

5. How to Check the Number of Installed Packages

If you want to know how many packages are currently installed on your system, Ubuntu provides simple commands for that. This can be helpful for understanding the overall system size and state.

Using the apt Command

You can combine the apt list command with a pipe (|) and wc -l to count the number of installed packages.

Command Example

apt list --installed | wc -l

Command Explanation

  • apt list --installed: Lists installed packages.
  • wc -l: Counts the number of lines, returning the total number of entries.

Example Output

543

In this example, 543 packages are installed on the system.

Using the dpkg Command

You can also count installed packages using dpkg-query combined with grep and wc:

Command Example

dpkg-query -l | grep '^ii' | wc -l

Command Explanation

  • dpkg-query -l: Lists installed packages.
  • grep '^ii': Filters only installed packages (those marked with ii).
  • wc -l: Counts the filtered lines.

Example Output

487

This example shows 487 installed packages.

Checking the Number of Snap Packages

To count Snap packages, use the snap list command:

Command Example

snap list | wc -l

Note

The snap list output includes a header row. To get the accurate number, subtract one:

snap list | tail -n +2 | wc -l

Summary

  • Apt command: apt list --installed | wc -l gives a quick count.
  • Dpkg command: dpkg-query -l | grep '^ii' | wc -l gives more precise results.
  • Snap command: snap list counts Snap packages.

These commands help you assess how many packages and Snap apps are currently installed on your Ubuntu system.

6. Summary

This article explained multiple methods for checking installed packages in Ubuntu. Each has its own advantages, and you can choose depending on your purpose.

Methods Covered in This Article

  1. Listing installed packages
  • Used apt list --installed and dpkg-query -l to list all installed packages.
  • For Snap packages, used snap list.
  1. Checking specific packages
  • Combined with grep to quickly verify whether a particular package is installed.
  1. Retrieving detailed information
  • Used apt show and dpkg -s to check version, dependencies, and details.
  1. Counting installed packages
  • Used wc -l to count total packages installed in the system.

Which Method Should You Use?

  • For beginners:
    Use the simple apt command, such as apt list --installed.
  • For detailed inspection:
    Use dpkg or apt show for deeper insights.
  • For Snap users:
    Use snap list to view only Snap packages.

Final Thoughts

Mastering these basic commands helps you efficiently manage Ubuntu packages. Use the methods introduced here to monitor your system’s state and troubleshoot issues effectively.

7. FAQ

Below are frequently asked questions about checking installed packages in Ubuntu, covering common issues for beginners and intermediate users.

Q1: What is the difference between apt and dpkg?

A:
apt is a high-level package manager commonly used in Ubuntu and Debian-based systems. It handles installation, removal, and updates from repositories. In contrast, dpkg is a lower-level tool used to manage local .deb packages directly. In fact, apt internally relies on dpkg.

Main differences:

  • apt: Downloads and installs packages from repositories automatically.
  • dpkg: Manages local .deb files without repository handling.

Q2: What are Snap packages?

A:
Snap is a modern package system developed by Ubuntu. Unlike traditional Debian packages, Snaps bundle all dependencies within themselves, allowing for easier cross-distribution installation. Key features include:

  • Advantages: Prevents dependency conflicts and allows the latest app versions.
  • Disadvantages: Can be larger in size and slower to launch.

Use snap list or snap install to manage Snap packages.

Q3: What is the easiest way to check if a specific package is installed?

A:
Use the following apt command:

apt list --installed | grep package-name

For example, to check if curl is installed:

apt list --installed | grep curl

If the package name appears in the output, it means the package is installed.

Q4: What should I do if a command doesn’t work?

A:
Follow these troubleshooting steps:

  1. Check for typos: Make sure the command is typed correctly.
  2. Verify permissions: Some commands require sudo. Try adding it and re-running the command.
sudo apt list --installed
  1. Update package lists: If package data is outdated, run:
sudo apt update
  1. Check logs: Review /var/log/syslog or journalctl for detailed errors.

Q5: How can I remove an installed package?

A:
Use apt remove or apt purge:

  • apt remove package-name: Removes the package but keeps configuration files.
  • apt purge package-name: Removes both the package and configuration files.

Example:

sudo apt remove curl

To also delete configuration files:

sudo apt purge curl

Q6: Can I save the list of installed packages to a file?

A:
Yes. You can export the list with the following command:

apt list --installed > installed_packages.txt

This saves all installed packages to installed_packages.txt. You can use this file to reinstall packages on another system if needed.

Conclusion

This FAQ covered common questions and answers about Ubuntu package management. Use these tips to make your system administration more efficient, and continue improving your command-line skills to handle future troubleshooting tasks with confidence.