0

When searching for packages in the apt repository we can use apt search <package-name> and apt-cache search <package-name> inside the terminal and we get a list of package names matching <package-name> with both the commands. Two questions -

  1. What's the major difference between the two commands?
  2. When to use which command over the other?
skekmal
  • 175

1 Answers1

1

apt is a more recent tool, combining functionality of the older tools apt-get, apt-cache, etc., and is aimed to be more optimized for interactive use.

Both apt search and apt-cache search serve to retrieve package names that fulfill a search criterion.

apt-cache search by default lists package name and short description on a single name:

~$ apt-cache search xvile 
vile - VI Like Emacs - vi work-alike
vile-common - VI Like Emacs - support files for vile/xvile
vile-filters - VI Like Emacs - highlighting filters for vile/xvile
xvile - VI Like Emacs - vi work-alike (X11)

apt also provides version information and architecture, in a two line format:

~$ apt search xvile
Sorting... Done
Full Text Search... Done
vile/jammy 9.8v-1build1 amd64
  VI Like Emacs - vi work-alike

vile-common/jammy,jammy 9.8v-1build1 all VI Like Emacs - support files for vile/xvile

vile-filters/jammy 9.8v-1build1 amd64 VI Like Emacs - highlighting filters for vile/xvile

xvile/jammy 9.8v-1build1 amd64 VI Like Emacs - vi work-alike (X11)

only searches package name and description. With the option provides a compact list of package name and description

With the --full option, apt-search provides full package info for all found packages:

~$ apt-cache search xvile --full
Package: vile
Architecture: amd64
Version: 9.8v-1build1
Priority: optional
Section: universe/editors
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Brendan O'Dea <bod@debian.org>

...information that with apt, can be retrieved with the show command for individual packages:

~$ apt show xvile
Package: xvile
Version: 9.8v-1build1
Priority: optional
Section: universe/editors
Source: vile
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Brendan O'Dea <bod@debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 1,509 kB

apt-cache search can be made to search package names only with the --names-only option:

~$ apt-cache search xvile --names-only 
xvile - VI Like Emacs - vi work-alike (X11)

Which one to use?

In principle, apt is developed specifically to be your more simple day-to-day interactive tool, but ultimately the choice is yours. All of these APT tools will continue to be around.

vanadium
  • 97,564