Package administration commands
part of its operation, APT uses a file that lists the 'sources'
from which packages can be obtained. This file is
The entries in this file normally follow this format:
deb http://host/debian distribution section1 section2 section3
deb-src http://host/debian distribution section1 section2 section3
Of course, the
above entries are fictitious and should not be used. The first
word on each line,
indicates the type of archive: whether it contains binary
that is, the pre-compiled packages that we normally use, or
source packages (deb-src),
which are the original program sources plus the Debian control
containing the changes needed for `debianizing' the program.
We usually find the following in
the default Debian sources.list:
# See sources.list(5) for more information, especially
# Remember that you can only use http, ftp or file URIs
# CDROMs are managed through the apt-cdrom tool.
deb http://http.us.debian.org/debian stable main contrib non-free
deb http://non-us.debian.org/debian-non-US stable/non-US main contrib non-free
deb http://security.debian.org stable/updates main contrib non-free
# Uncomment if you want the apt-get source function to work
#deb-src http://http.us.debian.org/debian stable main contrib non-free
#deb-src http://non-us.debian.org/debian-non-US stable/non-US main contrib non-free
These are the
lines needed by a basic Debian install. The first
line points to the official archive, the second to the non-US
archive and the third to the archive of Debian security updates.
The two last
lines are commented out (with a `#' in front), so apt-get will
ignore them. These are
lines, that is, they point to Debian source packages. If you
often download program sources for testing or recompiling,
file can contain several types of lines. APT knows how to deal
with archives of types
(local files, e.g., a directory containing a mounted ISO9660
that I know of.
Do not forget
after modifying the
file. You must do this to let APT obtain the package lists from
the sources you specified.
install a package APT retrieves the needed files from the hosts
listed in /etc/apt/sources.list,
stores them in a local repository (
and then proceeds with installation
Main package management tools
dpkg – Debian package file installer
apt-get – Command line front end for APT
aptitude – Advanced text and command line front end for APT
synaptic – Gtk GUI front end for APT
dselect – Menu-driven package manager
tasksel – Task installer
To install software using apt
-d Download only - do NOT install or unpack archives
-f Attempt to continue if the integrity check fails
-s No-act. Perform ordering simulation
-y Assume Yes to all queries and do not prompt
-u Show a list of upgraded packages as well
somehow damage an installed package, or simply want the files of
a package to be reinstalled with the newest version that is
available, you can use the
option like so:
# apt-get --reinstall install packagename
Updating the list of packages in
Update software using apt
#apt-get -u upgrade
To change the list of apt mirrors
Search for package
#apt-cache search package
Uninstall software using apt
#apt-get remove software
Shortcuts / Cheatcodes
update the package lists
# apt-get update
update the available package lists
# dselect update
upgrade all installed packages
# apt-get upgrade
# apt-get install pkg
# apt-get remove pkg
show all installed and removed
show install status of package
#dpkg -l pkg
show all packages that match
#dpkg -S pattern
list packages that contain string
list files in package
#dpkg -L pkg
show status of package
#dpkg -s pkg
show details of package
#dpkg -p pkg
list relevant packages
#apt-cache search string
install package from a deb file
# dpkg -i file.deb
# dpkg -P pkg
re-run the configure for a package
# dpkg-reconfigure pkg
get the source
# apt-get source pkg
build-deps for source and install as needed
# apt-get build-dep
install package from specific
# apt-get -t release install pkg
prevent name from running at
# update-rc.d -f name remove
upgrade the distribution
# apt-get –u dist-upgrade
How to know what packages may be
apt-show-versions is a program
that shows what packages in the system may be updated and
several useful information.
The -u option displays a list of
is now the preferred text front end for APT, the Advanced
Package Tool. It remembers which packages you deliberately
installed and which packages were pulled in through
dependencies; the latter packages are automatically de-installed
when they are no longer needed by any deliberately installed
packages. It has advanced package-filtering features but these
can be difficult to configure.
Update the local cache of available packages (formerly
Upgrade available packages (formerly apt-get upgrade).
available packages even if it means removing stuff (formerly
pkgname: Install package
(formerly apt-get install).
pkgname: Uninstall package
(formerly apt-get remove).
pkgname: Uninstall package
and config files (formerly apt-get –purge remove).
string: Search for a
package with “string” in the name or description (formerly
apt-cache search string).
pkgname: Show detailed of a
package (formerly apt-cache show pkgname).
Delete downloaded package files (formerly apt-get clean).
autoclean: Delete only
out-of-date package files but keep current ones (formerly
Fix a package at its current version and don’t upgrade it
automatically (formerly an obscure echo-to-file command). unhold
to remove the hold.
In short, fancy efforts
to create an optimized
did not produce a significant improvement for me from a location
in the USA. I manually chose a nearby site using
automatically, based on latency and bandwidth.
creates a more complete
but uses an inferior method of choosing the best mirror (ping
# aptitude install apt-spy
# cd /etc/apt ; mv sources.list sources.list.org
# apt-spy -d testing -l sources.apt
are a way of forcing
not to install a file into its default location, but to a
location. Diversions can be used through the Debian package
scripts to move a file away when it causes a conflict. System
administrators can also use a diversion to override a package's
configuration file, or whenever some files (which aren't marked
as conffiles) need to be preserved by
when installing a newer version of a package which contains
# dpkg-divert [--add] filename # add "diversion"
# dpkg-divert --remove filename # remove "diversion"
command is broken follow this
may make it impossible to install any
files. A procedure like the following will help you recover from
this situation. (In the first line, you can replace "links" with
your favorite browser command.)
$ links http://http.us.debian.org/debian/pool/main/d/dpkg/
... download the good dpkg_version_arch.deb
# ar x dpkg_version_arch.deb
# mv data.tar.gz /data.tar.gz
# cd /
# tar xzfv data.tar.gz
may also be used as the URL.
Local package archive
In order to create a
local package archive which is compatible with APT and the
needs to be created and package files need to be populated in a
particular directory tree.
deb repository similar to an
official Debian archive can be made in this way:
# aptitude install dpkg-dev
# cd /usr/local
# install -d pool # physical packages are located here
# install -d dists/unstable/main/binary-i386
# ls -1 pool | sed 's/_.*$/ priority section/' | uniq > override
# editor override # adjust priority and section
# dpkg-scanpackages pool override /usr/local/ \
# cat > dists/unstable/main/Release << EOF
# echo "deb file:/usr/local unstable main" \ >> /etc/apt/sources.list
Alternatively, a quick-and-dirty local
repository can be made:
# aptitude install dpkg-dev
# mkdir /usr/local/debian
# mv /some/where/package.deb /usr/local/debian
# dpkg-scanpackages /usr/local/debian /dev/null | \
gzip - > /usr/local/debian/Packages.gz
# echo "deb file:/usr/local/debian ./" >> /etc/apt/sources.list
These archives can be
remotely accessed by providing access to these directories
through either HTTP or FTP methods and changing entries in
is an on-demand package installation tool.
$ sudo auto-apt update
... update database
$ auto-apt -x -y run
Entering auto-apt mode: /bin/bash
Exit the command to leave auto-apt mode.
$ less /usr/share/doc/med-bio/copyright # access non-existing file
... Install the package which provide this file.
... Also install dependencies
Package Management Common errors
Errors will always happen, many of them caused by users not
paying attention. The following is a list of some of the most
frequently reported errors and how to deal with them.
If you receive a message that looks like the
one below when trying to run apt-get install package
Package Lists... Done
Building Dependency Tree... Done
W: Couldn't stat source package list 'http://people.debian.org
unstable/ Packages' (/var/state/apt/lists/people.debian.org_%7ekov_debian_unstable_Packages)
- stat (2 No such file or directory)
W: You may want to run apt-get update to correct these missing
E: Couldn't find package penguineyes
you forgot to run
apt-get update after your last change to the /etc/apt/sources.list
If the error looked like:
not open lock file /var/lib/dpkg/lock - open (13 Permission
E: Unable to lock the administration directory (/var/lib/dpkg/),
are you root?
trying any apt-get method other than source, you don't have root
permission, that is, you're running as a normal user.
There's an error similar to the above which
happens when you run two copies of apt-get at the same time, or
even if you try to run apt-get while a dpkg process is active.
The only method that can be used simultaneously with others is
the source method.
If an installation breaks in the middle of
the process and you find that it's no longer possible to install
or remove packages, try running these two commands:
apt-get -f install
# dpkg --configure -a
And then try again. It may be necessary to
run the second of the above commands more than once.
This is an important lesson for those
adventurers who use `unstable'.
If you receive the error
"E: Dynamic MMap ran out of room"
when running apt-get update,
following line to /etc/apt/apt.conf: