Package management using apt-get

Our support team receives a few queries each day about managing packages under Linux. All our installs have the APT toolset installed. We have a guide on some of the basic uses listed on our HowTo page.

There are a a number of uses which can make life easier which I will detail below, but it helps to have a bit of history to go with that. Apt was originally developed for use with Debian distributions as a fronted to the dpkg tool. dpkg has a number of different front-ends, one of the older better known options include dselect. Apt also works with the rpm repositories used by RHELTM, CentOS, and other derived distributions.

Lets take a look at some additional features. Some of the following is quoted from the apt-get man page which is written by Jason Gunthorpe and the APT development team

Cleaning up

apt-get purge <package-name>

purge is identical to remove except that all package files are removed (any configuration files are deleted too). This can be useful where you want to restore default behavior by doing a clean install, or ti simply get rid of unused cruft on your fileystem. Note that you can not do a purge after a remove, a purge operation should be done instead of.

 apt-get clean

This clears any archived/cached packages that were previously downloaded to be installed. It can be a great space saver on those occasions when you need that last little bit of disk space. You can also use this to sanitize already downloaded packages that may have become corrupt and therefore won't install properly.

apt-get check

"Updates the package cache and checks for broken [installed] dependencies."

Building sources

apt-get source <package-name>

"APT will examine the available packages to decide which source package to fetch. It will then find and download into the current directory"

apt-get build-dep <package-name>

"build-dep causes apt-get to install/remove packages in an attempt to satisfy the build dependencies for a source package."

Using options

You can also pass in a number of options to tweak how each command is run. There are to many to list here, but a couple that are worthy of note are...

-s, --simulate, --just-print, --dry-run, --recon, --no-act

No action; perform a simulation of events that would occur but do not actually change the system.


"This is a dangerous option that will cause apt to continue without prompting if it is doing something potentially harmful. It should not be used except in very special situations. Using force-yes can potentially destroy your system!". All of us support staff endorse the cautionary note here, if you are not sure, don't do it. apt-get us usually pretty good at working out dependencies so if you see a message telling you about that option, something is off. We are available 24/7 to help.

Apt also has a standard configuration file which can be tweaked by the options in various ways to change the default behavior. Usually that will be found under the folder /etc/apt/

Keeping packages at a known version

This is called pinning, and can be used to prevent certain packages from being upgraded or to revert to an older version. Wikipedia says...

The APT pinning feature allows administrators to force APT to choose particular versions of packages which may be available in different versions from different repositories. This allows administrators to ensure that packages are not upgraded to versions which may conflict with other packages on the system, or that have not been sufficiently tested for unwelcome changes.

One example of that is described on our recently updated Ubuntu upgrade guide for the rsyslog package. More information on pinning techniques can be had from the Debian documentation.


You should also check out the options for apt-cache, apt-key, apt-ftparchive, and some of the many other optional tools available.

About Glenn Enright

Linux Systems Administrator at I focus mainly on dedicated server provisioning with a sprinkling of network administration.
This entry was posted in Rimuhosting and tagged , , , , , . Bookmark the permalink.

2 Responses to Package management using apt-get

  1. Dave Potts says:

    As an end user you might want to look at aptitude as a nice wrapper round apt.

  2. Glenn Enright says:

    Absolutely, thats a great tool as well. On rpm based package systems yum works really well, especially with in the latest versions supporting compresion.