How to Easily Check Installed Packages on Ubuntu | A Comprehensive Guide to apt, dpkg, and snap

目次

1. Introduction

Ubuntu is a reliable Linux distribution used by many developers and engineers. There may be times when you need to check which packages are 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 this article, we will provide a detailed guide on how to check installed packages on Ubuntu. We will introduce practical methods that are useful for both beginners and intermediate users, so be sure to read through to the end.

2. How to List Installed Packages

There are several ways to check installed packages in Ubuntu. Here, we will introduce three commonly used methods. Each method has its own use case, so choose the one that best suits your needs.

Using the apt Command

The apt command is one of the most commonly used package management commands in Ubuntu. To list installed packages, use the following command:

apt list --installed

Command Explanation

  • apt list: Lists package information on your system.
  • --installed: Displays only installed packages.

Example Output

When you run the command, you will see a list of installed packages, like this:

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

Using the dpkg Command

The dpkg command is a low-level package management tool that directly handles Debian packages. You can check installed packages with the following command:

dpkg-query -l

Command Explanation

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

Example Output

Running the command will produce output like this:

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 installed correctly.

Using the snap Command

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

snap list

Command Explanation

  • snap list: Lists all installed Snap packages on your system.

Example Output

The command will display a list of installed Snap packages:

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

This command is useful for checking version and revision information of installed Snap packages.

Summary

  • apt list --installed: Useful for quickly checking installed packages.
  • dpkg-query -l: Provides more detailed package information.
  • snap list: Specifically for checking installed Snap 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 ways to check whether a specific package is installed. Here, we will explain how to use the apt and dpkg commands for this purpose.

Checking with the apt Command

You can use the apt command to easily search for a specific package in the list of installed packages.

Command Example

By combining it with grep, you can filter the results for a specific package:

apt list --installed | grep package-name

Example Usage

For instance, to check if the curl package is installed, use:

apt list --installed | grep curl

Example Output

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

The output confirms that curl is installed.

Checking with the dpkg Command

The dpkg command can also be used to check if a specific package is installed.

Command Example

Use the following command to display entries containing the specified package name:

dpkg-query -l | grep package-name

Example Usage

To check if the git package is installed, use:

dpkg-query -l | grep git

Example Output

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

Here, ii confirms that the package is correctly installed.

Checking Snap Packages

If the package was installed via Snap, use the snap command to check for its presence.

Command Example

snap list | grep package-name

Example Usage

To check if the chromium Snap package is installed, use:

snap list | grep chromium

Example Output

chromium    97.0.4692.99    1892   latest/stable    canonical✓    -

The output confirms that chromium is installed as a Snap package.

Summary

  • apt list --installed | grep package-name: A simple and easy method.
  • dpkg-query -l | grep package-name: Provides more detailed information.
  • snap list | grep package-name: Used for checking Snap packages.

By using these methods, you can quickly verify whether a required package is installed on your system. Choose the command that best fits your needs.

4. How to Display Detailed Information of Installed Packages

There are times when you need to check the details of an installed package, such as its functionality, dependencies, or version information. In Ubuntu, you can retrieve this information using the following commands.

Using the apt show Command

The apt show command is used to display detailed information about a specific package.

Command Example

apt show package-name

Example Usage

For example, to check the details of the curl package, enter:

apt show curl

Example Output

Package: curl
Version: 7.68.0-1ubuntu2.6
Priority: optional
Section: web
Maintainer: Ubuntu Developers 
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: The package name.
  • Version: The version of the package.
  • Section: The category the package belongs to (e.g., web, utils).
  • Maintainer: The package maintainer information.
  • Description: A brief overview of the package.

Using the dpkg Command

The dpkg command can also be used to check details of a specific package.

Command Example

dpkg -s package-name

Example Usage

To display details of the git package, enter:

dpkg -s git

Example Output

Package: git
Status: install ok installed
Priority: optional
Section: vcs
Maintainer: Ubuntu Developers 
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 essential details about the package, including its installation status.

Checking Dependencies

If you want to check the dependencies of a package, you can use the apt show command. For example, to check the dependencies of the curl package, use:

apt show curl

The output will include dependency information like this:

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

This allows you to see which other packages are required for the package to function properly.

Summary

  • apt show package-name: Useful for checking package details and dependencies.
  • dpkg -s package-name: Provides a more concise summary of package details.

By using these commands, you can gain insight into package details and dependencies, which is useful for system management 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 commands to easily check this information. This can be useful for understanding the system’s scale and status.

Using the apt Command

You can use the apt list command along with 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 in the output, representing the total number of installed packages.

Example Output

543

The output shows the total number of installed packages on the system. In this example, there are 543 installed packages.

Using the dpkg Command

You can also use dpkg-query to check the number of installed packages.

Command Example

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

Command Explanation

  • dpkg-query -l: Lists installed packages.
  • grep '^ii': Filters out lines that indicate installed packages.
  • wc -l: Counts the number of lines, showing the total installed packages.

Example Output

487

This indicates that 487 packages are installed on the system.

Checking the Number of Snap Packages

To check the number of Snap packages installed, use the snap list command:

Command Example

snap list | wc -l

Example Output

12

This indicates that 12 Snap packages are installed.

Summary

  • apt command: Use apt list --installed | wc -l to quickly check the total package count.
  • dpkg command: Use dpkg-query -l | grep '^ii' | wc -l for more detailed filtering.
  • Snap packages: Use snap list to count Snap-specific packages.

These methods allow you to quickly determine how many packages are installed on your system, helping with system monitoring and maintenance.

6. Conclusion

In this article, we covered various ways to check installed packages on Ubuntu. Each method has its strengths, so choose the one that best suits your needs.

Summary of Methods Covered

  • Listing installed packages: Using apt list --installed and dpkg-query -l.
  • Checking for a specific package: Using grep to filter results.
  • Retrieving package details: Using apt show and dpkg -s.
  • Counting installed packages: Using wc -l to count package entries.

Mastering these commands will help you efficiently manage Ubuntu packages. Use them to monitor and troubleshoot your system effectively!

7. FAQ

Here, we answer frequently asked questions about checking installed packages on Ubuntu. These cover common concerns for both beginner and intermediate users.

Q1: What is the difference between apt and dpkg?

A:
The apt command is a high-level package management tool used in Ubuntu and Debian-based Linux distributions. It simplifies package installation, removal, and updates. On the other hand, dpkg is a low-level command that directly manages installed packages. The apt command internally utilizes dpkg to handle package operations.

Main Differences:

  • apt: Uses repositories to download and install packages.
  • dpkg: Manages local Debian package files (.deb) directly.

Q2: What is a Snap package?

A:
Snap is a new package management system developed by Ubuntu. Unlike traditional Debian packages managed by apt and dpkg, Snap packages bundle all dependencies within a single package, making them portable across different systems.

  • Advantages: Avoids dependency conflicts and allows access to the latest versions of applications.
  • Disadvantages: Snap packages tend to be larger in size compared to traditional Debian packages.

To manage Snap packages, use commands like snap list and snap install.

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

A:
The simplest way is to use the apt command:

apt list --installed | grep package-name

For example, to check if curl is installed:

apt list --installed | grep curl

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

Q4: What should I do if the command does not work?

A:
Follow these troubleshooting steps:

  1. Check for typos: Ensure the command is entered correctly.
  2. Verify permissions: Some commands require sudo. Try running it with sudo:
sudo apt list --installed
  1. Update the package manager: If the package list is outdated, update it with:
sudo apt update
  1. Check system logs: Look for errors in /var/log/syslog or use journalctl to diagnose the issue.

Q5: How do I remove an installed package?

A:
Use the apt remove or apt purge commands.

  • apt remove package-name: Removes the package but keeps configuration files.
  • apt purge package-name: Completely removes the package along with its configuration files.

For example, to remove curl:

sudo apt remove curl

To remove it along with configuration files:

sudo apt purge curl

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

A:
Yes, you can save the list using the following command:

apt list --installed > installed_packages.txt

This will create a file named installed_packages.txt containing the list of installed packages. You can use this file to reinstall the same packages on another system using apt install.

8. Conclusion

In this article, we covered various methods for checking installed packages on Ubuntu. Each method has its unique advantages, so choose the one that best fits your requirements.

Summary of Covered Methods

  1. Listing installed packages
  • Used apt list --installed and dpkg-query -l to display all installed packages.
  • For Snap packages, we used snap list.
  1. Checking for a specific package
  • Used grep to filter the results and quickly check if a specific package is installed.
  1. Retrieving package details
  • Used apt show and dpkg -s to check version, dependencies, and maintainer information.
  1. Counting installed packages
  • Used wc -l to count installed packages.

Which Method Should You Use?

  • For beginners: Use the apt command (e.g., apt list --installed) for a simple approach.
  • For detailed package information: Use dpkg commands or apt show.
  • For Snap packages: Use snap list to manage them.

Final Thoughts

To efficiently manage your Ubuntu system, it’s essential to master these fundamental package management commands. Use the techniques introduced in this guide to monitor your system’s status and troubleshoot any issues.


年収訴求