Basic package management on command-line

So soon after praising the wonders of Synaptic, it's ironic that I should be giving instructions on how to manage Ubuntu packages using the command line.

Actually, the reason is simple. It's much faster to manage repository packages using command-line utilities rather than a GUI application. I've already said as much when I explained why I prefer the command line. Synaptic is great, but there comes a point when you outgrow it.

Previous documentation I've read immediately dive into apt-get install, which is the command and option to install a package. This is great if you already know what package you want to install. But what if you don't?

So that's why I prefer to start with the apt-cache.

According to its man page, apt-cache "performs a variety of operations on APT’s package cache. apt-cache does not manipulate the state of the system but does provide operations to search and generate interesting output from the package metadata."

That's quite a mouthful. Let me just give you the form I use it most often for, apt-cache search. This allows me to search the APT cache for the package name or functionality I want.

For example, I need to look for an appropriate BitTorrent client for my newly-installed Xubuntu 6.10 machine. (Xubuntu does not come with a pre-installed BitTorrent client.) What command would I use?

apt-cache search torrent

This command will look for the occurence of the search key "torrent" on either name or description in the APT cache. Sample output would be:

bittornado - bittorrent client with enhanced curses interface
bittorrent - Scatter-gather network file transfer
gnome-btdownload - Gnome interface for 'executing' BitTorrent files
ktorrent - BitTorrent client for KDE
azureus - BitTorrent client
azureus-gcj - BitTorrent client (native code)
bittornado-gui - bittorrent client with enhanced GUI interface

It turns out that bittornado sounds like the package I'm looking for. So now I would install it using sudo apt-get install:

sudo apt-get install bittornado

This will grab the package from its repository on the Internet, along with all its associated dependencies, and install them on my system.

If I want to verify if the package has been installed on my system, I would use the dpkg -l command with the -l option. As this provides a complete list of all installed packages, I would filter it with a search key using grep.

dpkg -l | grep bittornado

This gives the result:

ii bittornado 0.3.15-2ubuntu1 bittorrent client with enhanced curses inter

which indicates that bittornado has been installed.