D.1.  The apt System

[ fromfile: debian-tips.xml id: aptsystem ]

The apt system is a tool for managing packages and their dependencies. The following programs can be used to manage your apt-based package library.

Following are some handy tips and basic information about the apt system and how to use it.

[Tip] /etc/apt/sources.list

This file contains a list of sources that apt checks for packages. There are two things you should do with this sources list after a new install.

  1. Fix your main mirrors so that they point to a local mirror instead of a remote one. There are many ways to do this, but the most user-friendly way is to run apt-setup.

  2. Optional: Set the sources to "unstable" (debian) or "edgy" (kubuntu) if you want the latest and greatest versions of everything.[131]

  3. apt-get update downloads the package lists from your package sources so that you have a local copy of the lists, dependency relationships, and descriptions in your own dpkg database.

  4. Sometimes you know you want a package, but you can't remember its exact name. apt-cache search search-string searches through the locally downloaded package list for occurances of a string in the name or description of each package. If the returned list contains the package you were looking for, you can easily pull it down from the network and install it.

  5. Once you know the name of a package, you can read its full description with apt-cache show pkgname.

  6. apt-get install packageName is one of the most powerful commands you have, and it's only available if you have root access on a Debian-based system.

  7. apt-get remove packageName, as the name suggests, removes the named package in its entirety.

To save you time, I've listed a few packages which I suggest installing on a Debian system for C++ development. Note the use of the pound sign (#) to insert comments.

# alias for following commands:
alias agi='apt-get install -y'
# Database Stuff
agi mysql-server mysql-client libmysqlclient15-dev
agi sqlite3 libsqlite3-dev

# For development
agi build-essential manpages-dev # manual pages for stdlib
agi global cscope exuberant-ctags # For C++ development - navigation and doc generation
agi libqt4-dev qt4-dev-tools libphonon-dev
agi gstreamer0.10-fluendo-mp3 # for playing mp3 files in phonon
agi libtag1-dev libtag1-doc # taglib used by libfiletagger
agi gdb # gnu debugger
# UML Diagramming tool that reads/writes XMI and imports C++ source
agi umbrello 

More apt Tips

[Tip] apt-get (dist-|dselect-) upgrade

As time goes on, new packages are made available in your repository. When you want to upgrade your system, it is appropriate to do a dist-upgrade. To give apt permission to remove what are probably obsolete packages in favor of newer ones, use the command apt-get dselect-upgrade (which is similar but not exactly the same as what aptitude upgrade does).

[Tip] apt-get source packageName

Unless you need a specific version that is not served by your package source, you can grab a copy of the sourcecode in a convenient tarball for any available package by simply asking for it from apt.

[Tip] I just installed something - where did it go?

For this command, we drop down a level into dpkg land. dpkg is a quite powerful tool in its own right, but most of the time, we use it indirectly via apt-get. One useful option is dpkg -L packageName. This command lists all the files that were extracted from this package, and shows you the locations they now reside on your system.

[Tip] apt-get build-dep packageName

Sometimes, when compiling large packages (such as Qt), you run into the situation where the build fails due to missing libraries, (or their -dev packages). When I was still learning my way around my first Debian-based system, I was building apps and libraries by following a brute-force iterative process: configure, encounter and examine each error message, try to figure out what library is missing, install it, and repeat until no more errors. After I learned about apt-get build-dep, I realized immediately how much time I could have saved, and it was not insignificant!

You already know that the apt system is aware of which packages depend on which other packages, but with the apt-get build-dep packageName command, apt automatically downloads all the dependent libraries and their -dev packages, so that you have everything you need to build packageName. In other words, no more tracking down missing header files!

To see a list of all dependency relationships between packages, try apt-cache showpkg packageName.

apt-get build-dep libqt4-dev # grabs what you need to build qt4 from source
apt-get build-dep amarok # grabs headers and libs you need to build amarok
apt-get source amarok    # grabs the source tarball
[Tip] aptitude: When Your apt System Is Broken

Sometimes, you try to install something and not only do you get an error, but also apt is left in a state that is invalid. This is quite common when running unstable, less so when using testing. You might be instructed to try apt-get -f install, but after trying that, and also trying to remove the offending package, you are still stuck.

It is important to read the error message carefully: You almost always see references to specific package names that are causing the problems. By removing all of them, using apt-get remove pkg1 pkg2 pkg3, in one line, you can sometimes bring your system back into a valid state.

Another way to fix this is by using aptitude remove pkgN for each package. Aptitude can help you by finding and removing sets of related packages that are also causing problems.



[131] Ubuntu only: Be sure to add a "universe" after main so that you get the full packages offered by Ubuntu.