Finding Software in Ubuntu 12.04 from the command line

Finding Software in Ubuntu 12.04 from the command line

Sep 6, 2012

With so many packages available, it can be hard to find the exact thing you need using command-line APT. The general search tool is called apt-cache and is used like this:

djx@ubuntu:~$ apt-cache search kde

Depending on which repositories you have enabled, that tool returns about a thousand packages. Many of those results will not even have KDE in the package name, but will be matched because the description contains the word KDE.
You can filter through this information in several ways. First, you can instruct apt-cache to search only in the package names, not in their descriptions. This is done with the –n parameter, like this:

djx@ubuntu:~$ apt-cache –n search kde

Now the search has gone down from more than 1,000 packages to a few hundred. Another way to limit search results is to use some basic regular expressions, such as ^, meaning “start,” and $, meaning “end.” For example, you might want to search for programs that are part of the main KDE suite and not libraries (usually named something like libkde), additional bits (such as xmms-kde), and things that are actually nothing to do with KDE yet still match our search (like tkdesk). This can be done by searching for pack-ages that have a name starting with kde, as follows:

djx@ubuntu:~$ apt-cache –n search ^kde

Perhaps the easiest way to find packages is to combine apt-cache with grep, to search within search results. For example, if you want to find all games-related packages for KDE, you could run this search:

djx@ubuntu:~$ apt-cache search games | grep kde

When you’ve found the package you want to install, run it through apt-get install as per usual. If you first want a little more information about that package, you can use apt-cache show pkg, like this:

djx@ubuntu:~$ apt-cache showpkg mysql-server-5.0

This shows information on “reverse depends” (which packages require, recommend, or suggest mysql-server-5.0), “dependencies” (which packages are required, recommended, or suggested to install mysql-server-5.0), and “provides” (which functions this package gives you). The “provides” list is quite powerful because it allows different packages to provide a given resource. For example, a MySQL database-based program requires MySQL to be
installed, but isn’t fussy whether you install MySQL 4.1 or MySQL 5.0. In this situation, the Debian packages for MySQL 4.1 and MySQL 5.0 will both have “mysql-server-4.1” in the provides list, meaning that they offer the functionality provided by MySQL 4.1.
Therefore, you can install either version to satisfy the MySQL-based application.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>