A small APT-Guide Cookbook

What does APT mean?

APT is short for Advanced Packaging Tool and is a collection of programs and scripts that help both the sysadmin (in your case root) with the installation and management of deb-files but equally the system itself to know what is installed.

Sources List

The "APT" -system needs a config-file that contains information about the locations of the installable and upgradeable packages and is commonly referred to as a sources.list.

Sources are contained in a directory or folder named:
/etc/apt/sources.list.d/

Inside the folder are 2 files called:
/etc/apt/sources.list.d/debian.list and
/etc/apt/sources.list.d/aptosid.list

This has the benefit of easier (automated) mirror switching, and makes it safer to replace lists.

You can also add your own /etc/apt/sources.list.d/*.list files

All aptosid ISOs use the following sources as default:

#aptosid
# Free University Berlin/ spline (Student Project LInux NEtwork), Germany
deb ftp://ftp.spline.de/pub/aptosid/debian/ sid main fix.main
#deb-src ftp://ftp.spline.de/pub/aptosid/debian/ sid main fix.main

Further entries for non-free needs can be found in our always updated aptosid.list and debian.list:

#Debian
# Unstable
deb http://ftp.us.debian.org/debian/ unstable main contrib non-free
#deb-src http://ftp.us.debian.org/debian/ unstable main contrib non-free

# Testing
#deb http://ftp.us.debian.org/debian/ testing main contrib non-free
#deb-src http://ftp.us.debian.org/debian/ testing main contrib non-free

# Experimental
#deb http://ftp.us.debian.org/debian/ experimental main contrib non-free
#deb-src http://ftp.us.debian.org/debian/ experimental main contrib non-free

NOTE: In this example ftp.us indicates its using USA repositories.You may edit this file, as root, to use the repositories closest to you, simply by changing the country, that is, change ftp.us to ftp.nl, or ftp.uk. Most countries have local mirrors, thus bandwidth is conserved; speeds improved.

List of Debian Servers and mirrors current status.

To be able to obtain updated information on the packages APT uses a database. This database contains the packages but also which other packages are needed for that package to work (called dependencies). The program apt-get uses this database when installing your chosen packages to resolve all the dependencies and thereby to guarantee that the chosen packages will work. The updating of this database is done by the command apt-get update.

# apt-get update
	(which returns )
Get:1 http://aptosid.com sid Release.gpg [189B]
Get:2 http://aptosid.com sid Release.gpg [189B]
Get:3 http://aptosid.com sid Release.gpg [189B]
Get:4 http://ftp.de.debian.org unstable Release.gpg [189B]
Get:5 http://aptosid.com sid Release [34.1kB]
Get:6 http://ftp.de.debian.org unstable Release [79.6kB]

Installing a new package

Upgrading packages and installing new packages without stopping X can cause problems. Any method of installing packages under X has this problem.

As long as any package you want to install will not upgrade additional packages then it is safe to install it without stopping X. However if installing the package will cause other packages to upgrade, extreme caution should be taken and unless you are certain the packages which will be upgraded are not currently in use, you should stop X before installing the package.

If you are in any doubt ensure you leave X as per the dist-upgrade instructions before installing any packages. Upgrade an Installed System - dist-upgrade - The Steps .

Presuming the Apt-database is updated and the name of the package is known, then the following command will install a package called qemu, for example, and all its dependencies: (further on you will see how to search and find packages.)

# apt-get install pidgin
Reading package lists... Done
Building dependency tree... Done
The following extra packages will be installed:
  gconf-service gconf2 gconf2-common gstreamer0.10-gconf gstreamer0.10-nice
  gstreamer0.10-plugins-bad gstreamer0.10-plugins-good libavahi-glib1
  libcdaudio1 libdv4 libfftw3-3 libflite1 libgconf-2-4 libgconf2-4 libgme0
  libgnome-keyring-common libgnome-keyring0 libgssdp-1.0-3
  libgstfarsight0.10-0 libgstreamer-plugins-bad0.10-0 libgtkspell0
  libgupnp-1.0-4 libgupnp-igd-1.0-4 libiec61883-0 libmeanwhile1 libmimic0
  libmms0 libnice10 libofa0 libopenal-data libopenal1 libpurple0 librsvg2-2
  libslv2-9 libsoundtouch0 libsoup-gnome2.4-1 libspandsp2 libwildmidi-config
  libwildmidi1 libzbar0 libzephyr4 pidgin-data
Suggested packages:
  gconf-defaults-service frei0r-plugins libdv-bin oss-compat libfftw3-dev
  gnome-keyring tcl8.5 tk8.5 librsvg2-bin slv2-jack evolution-data-server
Recommended packages:
  gstreamer0.10-x ca-certificates libpurple-bin librsvg2-common freepats
The following NEW packages will be installed:
  gconf-service gconf2 gconf2-common gstreamer0.10-gconf gstreamer0.10-nice
  gstreamer0.10-plugins-bad gstreamer0.10-plugins-good libavahi-glib1
  libcdaudio1 libdv4 libfftw3-3 libflite1 libgconf-2-4 libgconf2-4 libgme0
  libgnome-keyring-common libgnome-keyring0 libgssdp-1.0-3
  libgstfarsight0.10-0 libgstreamer-plugins-bad0.10-0 libgtkspell0
  libgupnp-1.0-4 libgupnp-igd-1.0-4 libiec61883-0 libmeanwhile1 libmimic0
  libmms0 libnice10 libofa0 libopenal-data libopenal1 libpurple0 librsvg2-2
  libslv2-9 libsoundtouch0 libsoup-gnome2.4-1 libspandsp2 libwildmidi-config
  libwildmidi1 libzbar0 libzephyr4 pidgin pidgin-data
0 upgraded, 43 newly installed, 0 to remove and 0 not upgraded.
Need to get 40.6 MB of archives.
After this operation, 92.3 MB of additional disk space will be used.
Do you want to continue [Y/n]?

Deleting a package

Similarly it should come as no surprise that the following will deinstall a package, however it will not remove the dependencies:

apt-get purge pidgin
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  pidgin*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 2,270 kB disk space will be freed.
Do you want to continue [Y/n]? y
(Reading database ... 92990 files and directories currently installed.)
Removing pidgin ...
Purging configuration files for pidgin ...
Processing triggers for man-db ...
Processing triggers for gconf2 ...
Processing triggers for menu ...

In this last case the configuration files of the package 'pidgin' (basically how its setup) were not deleted from the system. You could use them when installing the same package again and it would work with these settings

If you want the config files deleted also, issue this command:

apt-get --purge remove pidgin
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  pidgin*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 2,270 kB disk space will be freed.
Do you want to continue [Y/n]? y
(Reading database ... 92990 files and directories currently installed.)
Removing pidgin ...
Purging configuration files for pidgin ...
Processing triggers for man-db ...
Processing triggers for gconf2 ...
Processing triggers for menu ...

Note the * after the package name in the output of apt . The asterisk in the output of apt indicates that the configuration files will also be removed.

Hold and/or Downgrade a package

Sometimes it may be necessary to rollback to a previous version of a package or put it on hold, due to a major bug with the latest version you have just installed.

Hold

echo package hold|dpkg --set-selections

To take a package off Hold

echo package install|dpkg --set-selections

To list packages on hold:

dpkg --get-selections | grep hold

Downgrading

Debian does not support downgrading packages. While it may work in simple cases, it could fail spectacularly for other packages. Please refer to Emergency downgrading.

Despite the fact that it is not supportable, downgrading has been known to work for simple packages. The steps for downgrading a simple package using kmahjongg as an example are:

  1. comment unstable sources in /etc/apt/sources.list.d/debian.list with a #
  2. Add testing sources in /etc/apt/sources.list.d/debian.list , for example:
    deb http://ftp.nl.debian.org/debian/ testing main contrib non-free
    
  3. apt-get update
    
  4. apt-get install kmahjongg/testing
    
  5. Put the newly installed package on hold with:
    echo kmahjongg hold|dpkg --set-selections
    
  6. comment <#>the testing sources in /etc/apt/sources.list.d/debian.list with and uncomment the unstable sources so that you get back to using unstable sources, then:
  7. apt-get update
    

When you do want to get the latest version of the package just do this:

echo kmahjongg install|dpkg --set-selections
apt-get update
apt-get install kmahjongg

apt-mark

apt-mark is a useful tool that shows you which packages are automatically or manually installed and offers the system administrator the opportunity to mark and hold packages that are not to be removed automatically. Read:

man apt-mark

Upgrade of an Installed System - dist-upgrade - Overview

If the whole system is to be upgraded this is achieved through a dist-upgrade. You should always check Current Warnings on the aptosid main web site, and check the warnings against the packages that your system wants to dist-upgrade. If you need to hold a package refer to Downgrade and Hold a package

An 'upgrade' only of 'debian sid' is not recommended.

Frequency of a dist-upgrade

dist-upgrade as routinely as you can, ideally once every week or two, at least 1 time per month to be safe. A dist-upgrade initiated only every 2 to 3 months should be considered the safe outer limit. For non-standard packages, or self compiled packages, you need to be much more careful with upgrading, since those may break your system at any time due to incompatibilities.

After the database is updated with apt-get update, one can find out which packages have new/newer versions: (first install apt-show-versions)

apt-show-versions -u
libpam-runtime/unstable upgradeable from 0.79-1 to 0.79-3
passwd/unstable upgradeable from 1:4.0.12-5 to 1:4.0.12-6
teclasat/unstable upgradeable from 0.7m02-1 to 0.7n01-1
libpam-modules/unstable upgradeable from 0.79-1 to 0.79-3.........

The update of a single package including its dependencies can for example (for gcc-4.0) be done with:

apt-get install gcc-4.0
Reading package lists... Done
Building dependency tree... Done
gcc-4.0 is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and xxx not upgraded

Just downloading

A little known and great option to do a check for what packages are in a dist-upgrade is the -d flag:

apt-get update && apt-get dist-upgrade -d

The -d allows you to download the dist-upgrade without installing it whilst in X from the konsole and allows you to do the dist-upgrade in init 3 at a later time. This also gives you the chance to check warnings against the list as it wisely gives you the option to proceed or abort like this:

apt-get dist-upgrade -d
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed:
  elinks-data
The following packages have been kept back:
  git-core git-gui git-svn gitk icedove libmpich1.0ldbl
The following packages will be upgraded:
  alsa-base bsdutils ceni configure-ndiswrapper debhelper
  discover1-data elinks file fuse-utils gnucash.........
35 upgraded, 1 newly installed, 0 to remove and 6 not upgraded.
Need to get 23.4MB of archives.
After this operation, 594kB of additional disk space will be used.
Do you want to continue [Y/n]?Y 

Y will download the upgraded packages without touching the installed system.

After the 'dist-upgrade -d' has downloaded, and wish to complete the dist-upgrade, immediately or at a later time, please follow these steps:

dist-upgrade - The Steps

NEVER EVER do a dist-upgrade nor upgrade whilst in X
Always check Current Warnings on the aptosid main web site. The warnings are there for a reason due to the very nature of unstable (Debian sid), which also updates 4 times per day.
## Log out of KDE.  
## Go to Textmode by doing Ctrl+Alt+F1
## logon as root, and then type:
service kdm stop  ##If using another window manager replace kdm, for example with gdm
apt-get update
apt-get dist-upgrade
apt-get clean
service kdm start ##If using another window manager replace kdm, for example with gdm
NEVER DIST-UPGRADE [or UPGRADE] with adept, synaptic or aptitude:

If you do not go to init 3, well tough for you, you have been warned!

The Reasons NOT to use anything else but apt-get for a dist-upgrade

Package managers like adept, aptitude, synaptic and kpackage are not always able to account for the huge amount of changes which happen in Sid (depedency changes, name changes, maintainer script changes, ...).

This is not the fault of the developers of those tools though, they write a excellent tools and fabulous for the debian stable branch, they are simply just not suitable for the very special needs of Debian Sid.

Use whatever you like to search for packages, but stick with apt-get for actually installing/removing/dist-upgrading.

Package managers like adept, aptitude, synaptic and kpackage are at the least, non-deterministic (for complex package selection), mix that with a quickly moving target like sid and even worse an external repository of questionable quality (we don't use or recommend those, but they're a reality on your user systems) and you will be courting disaster.

The other item to note is that all of these types of GUI package managers need to run in in X, and in doing a dist-upgrade in X, (or even an 'upgrade' which is not recommended), you will end up damaging up your system beyond repair, maybe not today or tomorrow, however in time you will.

apt-get on the other hand strictly does what it is asked to do, if there is any breakage you can pinpoint and debug/ fix the cause, if apt-get wants to remove half of the system (due to library transitions) it's the admin's call (that means you) to have at least a serious look.

This is the reason why debian builds use apt-get, not the other package manager tools.

Searching for a package with apt-cache

Another very useful command in the APT-system is apt-cache; it searches the APT-Database and shows information on packages; e.g. a list of all packages, that contain or address "aptosid" and "manual" is obtained by:

$ apt-cache search aptosid manual
.......
aptosid-manual-common - the official aptosid manual - common files
aptosid-manual-es - the official Spanish aptosid manual
aptosid-manual-de - the official German aptosid manual
aptosid-manual-el - the official Greek aptosid manual
aptosid-manual - the official aptosid manual - all languages
aptosid-manual-pt-br - the official Brazilian Portuguese aptosid manual
aptosid-manual-en - the official English aptosid manual
aptosid-manual-reader - aptosid manual reader

If you want more information on a particular package, you can use:

$ apt-cache show aptosid-manual-en
Package: aptosid-manual-en
Priority: optional
Section: doc
Installed-Size: 1088
Maintainer: Kel Modderman <kel@otaku42.de>
Architecture: all
Source: aptosid-manual
Version: 01.12.2007.06.03-1
Depends: aptosid-manual-common
Filename: pool/main/s/aptosid-manual/aptosid-manual-en_00.00.2010.08.14-1_all.deb
Size: 391222
MD5sum: 60f2175c3c5709745a4b4256ccc3c49d
SHA1: e275a0b27628b6aa210a4ced48d3646b438e78b8
SHA256: 2792580c7a091521301064180a1d0d8901f0a4af407b90432b9f8d8b6b3603ca
Description: the official en aptosid manual
 This manual is divided into common sections, for example, .......

All installable versions of the package (they depend on your sources.list) can be listed by typing:

$ apt-cache policy aptosid-manual-xx
aptosid-manual-xx:
  Installed: (none)
  Candidate: (none)
  Version table:
        500 http://aptosid.net sid/main Packages

A complete description of the APT-System can be found at APT-HOWTO

A complete description of the APT-System can be found at APT-HOWTO

Page last revised 31/12/2014 1540 UTC