Package administration commands
Basic
Configuration
As
part of its operation, APT uses a file that lists the 'sources'
from which packages can be obtained. This file is
/etc/apt/sources.list.
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,
deb
or
deb-src,
indicates the type of archive: whether it contains binary
packages (deb),
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
file (.dsc)
and the
diff.gz
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
deb
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
deb-src
lines, that is, they point to Debian source packages. If you
often download program sources for testing or recompiling,
uncomment them.
The
/etc/apt/sources.list
file can contain several types of lines. APT knows how to deal
with archives of types
http,
ftp,
file
(local files, e.g., a directory containing a mounted ISO9660
filesystem) and
ssh,
that I know of.
Do not forget
to run
apt-get update
after modifying the
/etc/apt/sources.list
file. You must do this to let APT obtain the package lists from
the sources you specified.
When you
install a package APT retrieves the needed files from the hosts
listed in /etc/apt/sources.list,
stores them in a local repository (/var/cache/apt/archives/),
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
#apt-get install
software
-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
If you
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
--reinstall
option like so:
# apt-get --reinstall install packagename
Updating the list of packages in
your sources.list
#apt-get update
Update software using apt
#apt-get -u upgrade
To change the list of apt mirrors
#apt-setup
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
installs package
# apt-get install pkg
uninstall package
# apt-get remove pkg
show all installed and removed
packages
#dpkg -l
show install status of package
#dpkg -l pkg
show all packages that match
pattern
#dpkg -S pattern
list packages that contain string
#dpkg
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
purge package
# dpkg -P pkg
re-run the configure for a package
# dpkg-reconfigure pkg
get the source
# apt-get source pkg
config
build-deps for source and install as needed
# apt-get build-dep
install package from specific
release
# apt-get -t release install pkg
prevent name from running at
bootup
# update-rc.d -f name remove
upgrade the distribution
# apt-get –u dist-upgrade
How to know what packages may be
upgraded
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
upgradeable packages:
#
apt-show-versions -u
aptitude
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
by
aptitude
when they are no longer needed by any deliberately installed
packages. It has advanced package-filtering features but these
can be difficult to configure.
aptitude update:
Update the local cache of available packages (formerly
apt-get update.
aptitude upgrade:
Upgrade available packages (formerly apt-get upgrade).
aptitude
dist-upgrade: Upgrade
available packages even if it means removing stuff (formerly
apt-get dist-upgrade).
aptitude install
pkgname: Install package
(formerly apt-get install).
aptitude remove
pkgname: Uninstall package
(formerly apt-get remove).
aptitude purge
pkgname: Uninstall package
and config files (formerly apt-get –purge remove).
aptitude search
string: Search for a
package with “string” in the name or description (formerly
apt-cache search string).
aptitude show
pkgname: Show detailed of a
package (formerly apt-cache show pkgname).
aptitude clean:
Delete downloaded package files (formerly apt-get clean).
aptitude
autoclean: Delete only
out-of-date package files but keep current ones (formerly
apt-get autoclean).
aptitude hold
pkgname:
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.
Optimized
sources.list
In short, fancy efforts
to create an optimized
sources.list
did not produce a significant improvement for me from a location
in the USA. I manually chose a nearby site using
apt-setup.
apt-spy
creates
sources.list
automatically, based on latency and bandwidth.
netselect-apt
creates a more complete
sources.list,
but uses an inferior method of choosing the best mirror (ping
time comparison).
# aptitude install apt-spy
# cd /etc/apt ; mv sources.list sources.list.org
# apt-spy -d testing -l sources.apt
The
dpkg-divert
command
File
diversions
are a way of forcing
dpkg
not to install a file into its default location, but to a
diverted
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
dpkg,
when installing a newer version of a package which contains
those files.
# dpkg-divert [--add] filename # add "diversion"
# dpkg-divert --remove filename # remove "diversion"
if the
dpkg
command is broken follow this
A broken
dpkg
may make it impossible to install any
.deb
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
$ su
password: *****
# ar x dpkg_version_arch.deb
# mv data.tar.gz /data.tar.gz
# cd /
# tar xzfv data.tar.gz
For i386,
http://packages.debian.org/dpkg
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
dselect
system,
Packages
needs to be created and package files need to be populated in a
particular directory tree.
A local
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/ \
> dists/unstable/main/binary-i386/Packages
# cat > dists/unstable/main/Release << EOF
Archive: unstable
Version: 3.0
Component: main
Origin: Local
Label: Local
Architecture: i386
EOF
# echo "deb file:/usr/local unstable main" \ >> /etc/apt/sources.list
Alternatively, a quick-and-dirty local
deb
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
/etc/apt/sources.list
accordingly.
auto-apt command
auto-apt
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
Reading
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
files
E: Couldn't find package penguineyes
you forgot to run
apt-get update after your last change to the /etc/apt/sources.list
file.
If the error looked like:
E: Could
not open lock file /var/lib/dpkg/lock - open (13 Permission
denied)
E: Unable to lock the administration directory (/var/lib/dpkg/),
are you root?
when
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,
add the
following line to /etc/apt/apt.conf:
APT::Cache-Limit
10000000;