A Little About Linux: Package Management with DEB and APT

One of the good things about Linux is the tools that it provides to manage software installation and removal.  There are two main ways to go about this management; RPM/YUM on Red Hat/CentOS/SUSE systems and DEB/APT on Debian/Ubuntu/Mint systems.  This page describes the latter system.

Not too amazingly, DEB packages are associated with Debian systems and those derived from the Debian distribution.  DPKG is the package management software that manages the DEB packages.

APT on the other hand, standing for Advanced Packaging Tool, manages the deployment, dependencies and updates of DEB packages and allows for searching and control of software repositories. 

Anatomy of an DEB file and Operations
The naming convention for an DEB file is;

debname_a.b.c-d.arch.deb

debname - You may have gathered what this is, this is is the name of the application in the package, although there are strange naming conventions just to keep you on your toes.  For instance, the Apache HTTP Server will normally be called 'httpd'... and these may be different on different Linux distributions.

a.b.c -  The package version number, this is normally the version of the program in the package.

d - The build or release number comes next, and this represents that minor changes made by the packager not the author of the code.

arch - This represents the architecture the package was built for, this could  be i386i586i686 and x86-64 depending on the binary.

Some useful DPKG commands and options;

Installs the Apache HTTP application or updates it if it is already installed:
dpkg -i apache2_2.2.22-13+deb7u3.amd64.deb

Uninstalls the package:
dpkg -P apache2_2.2.22-13+deb7u3

List all of the files in the installed package:
dpkg -L apache2

List all of the packages installed on the machine:
dpkg -l apache2

List the package a particular file was installed from:
dpkg -S /usr/share/bug/apache2/script

Show information about any installed package:
dpkg -p apache2

Using APT-CACHE and APT-GET
The APT group of applications largely duplicate what the YUM system does but is arguably a more comprehensive toolkit. The first of these tools, apt-cache deals entirely with the Debian package database (cache).  apt-get houses the more common YUM equivalent commands, it is a meta-packager and it allows the user to search and locate packages in multiple repositories on the Internet and locally and will also download and install them on the machine.  These commands are listed below;

apt-cache showpkg apache2 Shows additional package information.

apt-cache stats - Shows statistics about the packages and the cache.

apt-cache unmet - Lists all unmet dependencies on the system. 

apt-cache depends apache2 - Shows an applications dependencies.

apt-cache pkgnames - Shows all installed packages on a system.

As an example, we'll try and search for, install and then remove the Midnight Commander File Manager.

Search for a name, summary or description to find a specific package;
# apt-cache search "midnight commander"

mc-data - Midnight Commander - a powerful file manager -- data files

mc - Midnight Commander - a powerful file manager

Find out more information about a specific package;
# apt-cache show mc

Package: mc
Version: 3:4.8.3-10
Installed-Size: 1300
Maintainer: Debian MC Packaging Group <pkg-mc-devel@lists.alioth.debian.org>
Architecture: amd64
Depends: e2fslibs (>= 1.42.2), libc6 (>= 2.11), libcomerr2 (>= 1.01), libglib2.0-0 (>= 2.24.0), libgpm2 (>= 1.20.4), libslang2 (>= 2.2.4), mc-data (= 3:4.8.3-10)
Recommends: mime-support, unzip, perl
Suggests: zip, bzip2, links | w3m | lynx, arj, file, xpdf | pdf-viewer, dbview, odt2txt, gv, catdvi, djvulibre-bin, imagemagick, python, python-boto, python-tz
Description-en: Midnight Commander - a powerful file manager
 GNU Midnight Commander is a text-mode full-screen file manager. It
 uses a two panel interface and a subshell for command execution. It
 includes an internal editor with syntax highlighting and an internal
 viewer with support for binary files. Also included is Virtual
 Filesystem (VFS), that allows files on remote systems (e.g. FTP, SSH
 servers) and files inside archives to be manipulated like real files.
Homepage: http://www.midnight-commander.org
Description-md5: 252a5c5aeeb7425db45357d4ab8aa55f
Tag: admin::filesystem, implemented-in::c, implemented-in::perl,
 interface::commandline, interface::text-mode, role::program,
 scope::application, suite::gnu, uitoolkit::ncurses, use::browsing,
 use::editing, use::organizing, works-with::archive, works-with::file
Section: utils
Priority: optional
Filename: pool/main/m/mc/mc_4.8.3-10_amd64.deb
Size: 470358
MD5sum: 9e412f6352b2b013a8e15ea88a48b21e
SHA1: 8362913a55345e183ac93824358e33b2569a18a9
SHA256: 2d3fe9dde39183b41477446ac013fc3bb4df9be4500173aa21f5760b0f1242d3

Install the specified package from a repository, also including dependencies;
# apt-get install mc

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  mc-data
Suggested packages:
  zip arj dbview odt2txt gv catdvi djvulibre-bin python-boto python-tz
The following NEW packages will be installed:
  mc mc-data
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,556 kB of archives.
After this operation, 6,252 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://http.debian.net/debian/ wheezy/main mc-data all 3:4.8.3-10 [1,086 kB]
Get:2 http://http.debian.net/debian/ wheezy/main mc amd64 3:4.8.3-10 [470 kB]
Fetched 1,556 kB in 1s (1,255 kB/s)
Selecting previously unselected package mc-data.
(Reading database ... 126224 files and directories currently installed.)
Unpacking mc-data (from .../mc-data_3%3a4.8.3-10_all.deb) ...
Selecting previously unselected package mc.
Unpacking mc (from .../mc_3%3a4.8.3-10_amd64.deb) ...
Processing triggers for hicolor-icon-theme ...
Processing triggers for man-db ...
Processing triggers for menu ...
Processing triggers for desktop-file-utils ...
Processing triggers for gnome-menus ...
Setting up mc-data (3:4.8.3-10) ...
Setting up mc (3:4.8.3-10) ...
update-alternatives: using /usr/bin/mcview to provide /usr/bin/view (view) in auto mode
Processing triggers for menu ...

To check to see if there are any updates available;
#  apt-get --simulate update

Hit http://security.debian.org wheezy/updates Release.gpg
Get:1 http://http.debian.net wheezy Release.gpg [1,655 B]
Hit http://security.debian.org wheezy/updates Release
Hit http://http.debian.net wheezy-updates Release.gpg
Hit http://http.debian.net wheezy Release
Hit http://http.debian.net wheezy-updates Release
Hit http://security.debian.org wheezy/updates/main Sources
Get:2 http://http.debian.net wheezy/main Sources [5,957 kB]
Hit http://security.debian.org wheezy/updates/contrib Sources
Hit http://http.debian.net wheezy/main amd64 Packages
Hit http://security.debian.org wheezy/updates/main amd64 Packages
Hit http://http.debian.net wheezy/main Translation-en
Hit http://security.debian.org wheezy/updates/contrib amd64 Packages
Hit http://http.debian.net wheezy-updates/main Sources
Hit http://security.debian.org wheezy/updates/contrib Translation-en
Hit http://http.debian.net wheezy-updates/main amd64 Packages/DiffIndex
Hit http://security.debian.org wheezy/updates/main Translation-en
Hit http://http.debian.net wheezy-updates/main Translation-en/DiffIndex
Fetched 5,958 kB in 3s (1,510 kB/s)
Reading package lists... Done

Update a specific package to the latest version;
 apt-get --only-upgrade install cpio

Reading package lists... Done
Building dependency tree
Reading state information... Done
cpio is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Shows all of the dependencies of a specified package;
apt-cache depends mc

mc
  Depends: e2fslibs
  Depends: libc6
  Depends: libcomerr2
  Depends: libglib2.0-0
  Depends: libgpm2
  Depends: libslang2
  Depends: mc-data
  Suggests: zip
  Suggests: bzip2
 |Suggests: links
 |Suggests: w3m
  Suggests: lynx
  Suggests: arj
  Suggests: file
 |Suggests: xpdf
  Suggests: <pdf-viewer>
    epdfview
    evince
    evince-gtk
    gv
    okular
    viewpdf.app
    xpdf
    zathura
  Suggests: dbview
  Suggests: odt2txt
  Suggests: gv
  Suggests: catdvi
  Suggests: djvulibre-bin
  Suggests: imagemagick
    graphicsmagick-imagemagick-compat
  Suggests: python
  Suggests: python-boto
  Suggests: python-tz
  Recommends: mime-support
  Recommends: unzip
  Recommends: perl

Remove the specified package from the machine;
# apt-get remove mc

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
  mc-data
Use 'apt-get autoremove' to remove it.
The following packages will be REMOVED:
  mc
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 1,331 kB disk space will be freed.
Do you want to continue [Y/n]? y
(Reading database ... 126526 files and directories currently installed.)
Removing mc ...
update-alternatives: using /usr/bin/vim.tiny to provide /usr/bin/view (view) in auto mode
Processing triggers for desktop-file-utils ...
Processing triggers for gnome-menus ...
Processing triggers for menu ...

Cleans the APT cache directory;
#  apt-get clean

No comments :