Thursday, 24 January 2008

apt-cache

We've touched on installing packages from the command line, but to do so you have to know the name of the package you want to install. Sometimes you may know the kind of thing you want to install (such as a web browser or IM client) but not have any idea what different choices you have. Other times you may have some idea of the name of the package but not know exactly what it's called.

Now, you could use the package manager for this, but why go to the effort of starting up a graphical application that will take ages to work when the command line can do it quicker and more simply for you? Since Apt is the tool used by all these applications anyway, you might as well use it directly and get the job done quicker and more easily?

Apt has more than just apt-get up its sleeve. The apt-cache command allows you to search through both descriptions and package names, allowing you to look for a specific application, or for a type of application. This makes it a powerful and flexible tool.

First of all, let's run the following:
sudo apt-get update
That's just to make sure that you have the latest package lists from the repositories. Now, let's search for the Epiphany web browser:
matthew@matthew-laptop:~$ apt-cache search epiphany
epiphany - clone of Boulder Dash game
epiphany-data - required maps for epiphany game
epiphany-extension-gwget - Gwget extension for Epiphany web browser
libmozjs-dev - Development files for the Mozilla SpiderMonkey JavaScript library
libmozjs0d - The Mozilla SpiderMonkey JavaScript library
libmozjs0d-dbg - Development files for the Mozilla SpiderMonkey JavaScript library
peercast-handlers - P2P audio and video streaming handlers
flashplugin-nonfree - Adobe Flash Player plugin installer
epiphany-browser - Intuitive GNOME web browser
epiphany-browser-dev - Development files for Epiphany web browser
epiphany-extensions - Extensions for Epiphany web browser
matthew@matthew-laptop:~$
Apt-cache displays a list of all packages including the word "epiphany". There's no need for sudo as apt-cache makes no changes to your system. Similarly, if you wanted to search for a web browser, you could input the following:
apt-cache search "web browser"
In this example, as I want to search specifically for the term "web browser" rather than the two terms "web" and "browser", I've put them in quotes. That limits apt-cache to displaying applications which have the term "web browser" in their name or description, rather than either of the words individually, allowing you to narrow down the search parameters somewhat.

You can also use apt-cache to find other information about a package. For example, try this:
apt-cache depends epiphany-browser
will display a list of the dependencies required to run the Epiphany web browser. And this:
apt-cache show epiphany-browser
allows you to read the description for a package file.

In combination, apt-get and apt-cache allow you to install and remove packages, search for them and find out information about them. It's quicker and often easier to install from the command line once you get used to the tools. I hardly ever use a graphical application to install new software now - I just find it so much easier to use the command line.

If you were concerned about having to use the command line, hopefully these lessons have made you feel better about it. The best way to learn about the command line is to use it, and I hope you'll try to get into the habit of installing new packages from the command line, rather than going to the bother of starting up a resource-hungry graphical installer.

1 comment:

Keshav Khera said...

Nice post matthew, apt-cache is certainly a useful command