FactorPad
Build a Better Process

Linux apt-cache Command Summary with Examples

Linux apt-cache allows you to search for packages and dependencies.
  1. Purpose - Learn what apt-cache is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with apt-cache.
  4. A tip - Finish off with one more insight.
face pic by Paul Alan Davis, CFA
Updated: February 24, 2021
In this tutoral on Linux apt-cache, 66 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / apt-cache-command.html


An ad-free and cookie-free website.


Examples of the Linux apt-cache Command

Beginner

Learn to search for packages and dependencies at the Linux command line.

Video Tutorial

Videos can also be accessed from the Linux Essentials Playlist on YouTube.

Linux apt-cache Command Summary with Examples (4:00)

Video Script

The Command and Why You Need It

Our sixty-sixth word, or command to memorize is apt-cache from our category System.

apt-cache allows you to search for packages and dependencies.

Common Linux apt-cache Options
-options description
-h, --help Print help screen
-n, --names-only Search the name field only

Recall from the last video on apt-get we saw online repositories and apt-cache will help us find what packages are available.

Before we start, it helps to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The apt-cache command has 23 options and the argument can be a search term like a software package name. There are also, let's call them, sub-commands and an example is entered like this: apt-cache [-options] search package name.

Like most commands, help is available with double-dash --help. The -n option used in searches only accesses the name field, instead of the description (field).

Make note, separate commands apply to two types of Linux distributions, Debian-style is apt-cache, here, and in Fedora it's yum.

So why is apt-cache an important command? Well, you need a way to find out what you're missing out on, well at least in your Linux life. And now you know how to do that.

Demonstration

Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go. Start with a stats of the local cache file downloaded in our last apt-get update.

$ apt-cache stats Total package names: 56584 (1,132 k) Total package structures: 56589 (3,169 k) Normal packages: 43871 Pure virtual packages: 592 Single virtual packages: 4687 Mixed virtual packages: 522 Missing: 6917 Total distinct versions: 48120 (3,465 k) Total distinct descriptions: 45013 (1,080 k) Total dependencies: 303304 (8,490 k) Total ver/file relations: 922273 (2,215 k) Total Desc/File relations: 45013 (1,080 k) Total Provides mappings: 8302 (166 k) Total globbed strings: 80 (695 ) Total dependency version space: 1,264 k Total slack space: 43.0 k Total space accounted for: 17.5 M $ clear

And it has over 50,000 package names. Impressive huh?

Next, I'll do a search for the word nano, a text editor we know about, and then pipe it to a word count, for lines that is, to see both how many are out there in both the name and description fields, then just the name fields only. And this will take a second to show up and code up here, so bear with me.

$ apt-cache search nano | wc -l; apt-cache -n search nano | wc -l 23 16

Okay, very good, you can see each one there, description fields with names (23) and then also names only (16). We narrowed our search (from 50,000+ package names), so let's see the 16 name field results.

$ apt-cache -n search nano science-nanoscale-physics - Debian Science Nanoscale Physics packages science-nanoscale-physics-dev - Debian Science Nanoscale Physics development packages kiki-the-nano-bot - 3D puzzle game, mixing Sokoban and Kula-World kiki-the-nano-bot-data - Kiki the nano bot - game data libnanoxml2-java - small XML parser for Java libnanoxml2-java-doc - documentation for libnanoxml2-java nano - small, friendly text editor inspired by Pico nano-tiny - small, friendly text editor inspired by Pico - tiny build nanoblogger - Small weblog engine for the command line nanoblogger-extra - Nanoblogger plugins nanoc - static site generator written in Ruby nanoc-doc - static site generator written in Ruby - documentation libnanomsg-dev - nanomsg development files libnanomsg0 - high-performance implementation of scalability libraries libnanomsg0-dbg - high-performance implementation of scalability libraries - debug symbols nanopolish - consensus caller for nanopore sequencing data

And there they all are.

Nano, nano, nano ;) (Mork and Mindy, haha)

And last, let's use showpkg for details on this package nano.

$ apt-cache showpkg nano Package: nano Versions: 2.2.6-3 (/var/lib/apt/lists/gce%5fdebian%5fmirror.storage.googleapis.com_dists_jessie_main_binary-amd64_Packag es.gz) (/var/lib/apa/lists/deb.debian.org_debian_dists_jessie_main_binary-amd64_Packages.gz) (/var/lib/dpkg/st atus) Description Language: File: /var/lib/apt/lists/gce%5fdebian%5fmirror.storage.googleapis.com_dists_jessie_main_binar y-amg64_packages.gz MDS: b7eld8c3d813218742cfe8ae2996b595 Reverse Depends: dms-core,nano dms,nano junior-writing, nano Dependencies: 2.2.6-3 - dpkg (18 1.15.4) install info (0 (null) libc6 (2 2.14) libncursesw5 (2 5.6+20070909) libtinfo5 (0 ( null)) spell (0 (null)) pico (0 (null)) alpine-pico (1 2.00+dfsg-5) pico (0 (null) Provides: 2.2.6-3 - editor Reverse Provides:

A Final Tip

Okay now you know how to use apt-cache. And you know the syntax for commands, options and arguments.

One last tip about the apt-cache command. So the command helps resolve when packages are dependent on other packages. So read up on that.

Okay, thanks for visiting today. I hope this was a helpful introduction to the apt-cache command.


Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:


What's Next?

Help keep this free from annoying ad banners and show your support with a YouTube Channel subscription. Also, for updates follow @factorpad on Twitter.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / apt-cache-command.html


apt cache
apt cache search
apt cache stats
apt get update
apt cache showpkg
apt cache pkgnames
apt list packages
debian search packages
apt search package
apt cache clean
apt cacher
apt cache tutorial
apt cache examples
man apt cache

A newly-updated free resource. Connect and refer a friend today.