Methods for Searching Packages with Ubuntu apt-cache

In Ubuntu systems, we often need to install and update software, and apt-cache is a very useful tool that belongs to the APT (Advanced Package Tool) package management system. It is specifically designed for querying detailed information about software packages. Whether you want to know the name of a software or understand the specific details of an installed software, apt-cache can help.

一、Basic Search: Quickly Find Packages Containing Keywords

The most commonly used apt-cache search command is search, which lists related software packages based on keywords (package names or descriptions).

Command Format:

apt-cache search <keyword>

Here, the “keyword” can be the software name, functional description, or even a technical term (e.g., “editor”, “python”).

Example:
If you want to install a text editor but don’t know the package name, only knowing it is related to “text editing”, you can search:

apt-cache search text editor

The system will return results similar to the following:

nano - small, friendly text editor
vim - Vi IMproved - enhanced vi editor
gedit - GNOME text editor
libtext-editor-perl - Perl module for editing text files

The beginning of each line is the package name (e.g., nano), followed by a brief description (e.g., “small, friendly text editor”).

二、Exact Search: Match Only Package Names

If a keyword may appear in the descriptions of multiple software (e.g., searching “python” includes many related packages), use the --names-only parameter to make the search only match package names, avoiding overly redundant results.

Command Format:

apt-cache search --names-only <keyword>

Example:
To find all packages starting with “python3”, a direct search might include packages with “python3” in their descriptions. Using --names-only makes it more precise:

apt-cache search --names-only python3

The results will focus more on packages whose names contain “python3”, such as:

python3 - interactive high-level object-oriented language (default python3 version)
python3-pip - Python package manager
python3-dev - header files and a static library for Python (default)

三、View Detailed Information About a Package

To learn specific information about a software package (e.g., version, installed size, dependencies), use the show command.

Command Format:

apt-cache show <package_name>

Example:
To know detailed information about the “nano” text editor, execute:

apt-cache show nano

The output will include extensive information; focus on the following sections:
- Package: nano:Package name;
- Version: 6.2-1ubuntu1:Current installed version;
- Installed-Size: 424:Disk space occupied after installation;
- Description-en: small, friendly text editor:Detailed description (including features, usage scenarios, etc.);
- Depends: libc6 (>= 2.34), libncursesw6 (>= 6), libtinfo6 (>= 6):Dependent software packages.

四、Advanced Tips: Search Combined with Software Source Status

If you want to search for installed or upgradable packages, you can combine with apt or dpkg tools. These are advanced usages; beginners can learn them temporarily:

  • Search installed packages: First, use apt list --installed to list all installed packages, then filter with grep (e.g., apt list --installed | grep python);
  • Search upgradable packages: apt list --upgradable shows updatable software packages, and combining with grep quickly locates them.

五、Precautions

  1. Update the software source: It is recommended to execute sudo apt update before searching to update the software source list and ensure the search results include the latest packages;
  2. Keyword accuracy: If no results are found, check if the keyword is spelled correctly (e.g., “python” should not be misspelled as “pytho”);
  3. Avoid installing unknown packages: When installing software, confirm the package name and description via apt-cache show to avoid installing malicious software.

Summary

apt-cache is a “Swiss Army knife” for querying software packages in Ubuntu. Master the following core commands to quickly locate the required software:
- apt-cache search <keyword>: Basic search, matching package names and descriptions;
- apt-cache search --names-only <keyword>: Only matches package names for more precise results;
- apt-cache show <package_name>: View detailed information about a software package.

Skillfully using these commands will help you find, install, and manage software in the Ubuntu system more efficiently!

Xiaoye