3/30/10

A Debian Package Primer: Part One | Linux Magazine

A Debian Package Primer: Part O

The Advanced Package Tool (APT) is a command line tool that allows you to download install software packages and their dependencies to your system. Note the magical words, “and their dependencies.” This aspect of tools like apt-get justifies their use on any system, desktop or server.

APT is an all-in-one tool for managing software on your system. With it, you don’t really need any other tool or program for package management. The Debian distribution and its offspring enjoy the most comprehensive list of available software packages available for Linux.

There are still those rare occasions when you’ll need to download and install software using the classic tarball: unzip, untar, configure, make, make install format.

Sources Update

Using the apt-get command is simple. It always follows the syntax:

$ sudo apt-get command package 

The entry is optional if you’re updating, upgrading or performing non-package specific tasks. Several interactive examples will illustrate its use. In this first example, use apt-get to update the /etc/apt/sources.list file. The/etc/apt/sources.list file is a list of your configured repositories from which apt-get will download packages. This file can list both local (disk or CD/DVD) and remote package sources.

$ sudo apt-get update  Hit http://distro.ibiblio.org lenny Release.gpg Ign http://distro.ibiblio.org lenny/main Translation-en_US Hit http://distro.ibiblio.org lenny Release Hit http://volatile.debian.org lenny/volatile Release.gpg Ign http://volatile.debian.org lenny/volatile/main Translation-en_US Ign http://distro.ibiblio.org lenny/main Packages/DiffIndex Hit http://volatile.debian.org lenny/volatile Release Ign http://volatile.debian.org lenny/volatile/main Packages/DiffIndex Hit http://distro.ibiblio.org lenny/main Packages Ign http://volatile.debian.org lenny/volatile/main Sources/DiffIndex Hit http://volatile.debian.org lenny/volatile/main Packages Hit http://volatile.debian.org lenny/volatile/main Sources Hit http://security.debian.org lenny/updates Release.gpg Ign http://security.debian.org lenny/updates/main Translation-en_US Hit http://security.debian.org lenny/updates Release Ign http://security.debian.org lenny/updates/main Packages/DiffIndex Ign http://security.debian.org lenny/updates/main Sources/DiffIndex Hit http://security.debian.org lenny/updates/main Packages Hit http://security.debian.org lenny/updates/main Sources Reading package lists... Done 

Upgrade All Packages

To upgrade all packages for which upgrades exist, use:

$ sudo apt-get upgrade   Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be upgraded:   cups cups-bsd cups-client cups-common curl dpkg dpkg-dev drupal6 libapache2-mod-php5 libavcodec51   libavformat52 libavutil49 libcups2 libcupsimage2 libcupsys2 libcurl3 libcurl3-gnutls libmozjs1d libpango1.0-0   libpango1.0-common libpostproc51 libpulse0 libsmbclient libwbclient0 linux-headers-2.6.26-2-686   linux-headers-2.6.26-2-common linux-image-2.6.26-2-686 linux-libc-dev php5 php5-common php5-gd php5-mysql sudo   xulrunner-1.9 xulrunner-1.9-gnome-support 35 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Need to get 49.9MB of archives. After this operation, 115kB of additional disk space will be used. Do you want to continue [Y/n]? 

Typing a ‘Y’ at the prompt will download and install the listed packages.

Installing Packages

You also use apt-get to install individual packages and their dependencies.

$ sudo apt-get install abiword  apt-get install abiword Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed:   abiword-common abiword-help abiword-plugin-grammar abiword-plugin-mathview latex-xft-fonts   libaiksaurus-1.2-0c2a libaiksaurus-1.2-data libaiksaurusgtk-1.2-0c2a libgdome2-0 libgdome2-cpp-smart0c2a   libgoffice-0-4 libgoffice-0-common libgsf-gnome-1-114 libgtkmathview0c2a liblink-grammar4 libloudmouth1-0   libots0 libwv-1.2-3 link-grammar-dictionaries-en Suggested packages:   abiword-plugin-goffice The following NEW packages will be installed:   abiword abiword-common abiword-help abiword-plugin-grammar abiword-plugin-mathview latex-xft-fonts   libaiksaurus-1.2-0c2a libaiksaurus-1.2-data libaiksaurusgtk-1.2-0c2a libgdome2-0 libgdome2-cpp-smart0c2a   libgoffice-0-4 libgoffice-0-common libgsf-gnome-1-114 libgtkmathview0c2a liblink-grammar4 libloudmouth1-0   libots0 libwv-1.2-3 link-grammar-dictionaries-en 0 upgraded, 20 newly installed, 0 to remove and 0 not upgraded. Need to get 9295kB of archives. After this operation, 29.6MB of additional disk space will be used. Do you want to continue [Y/n]? y 

Removing Packages

The apt-get utility is equally good at uninstalling packages:

$ sudo apt-get remove tcpdump  Reading package lists... Done Building dependency tree Reading state information... Done Package tcpdump is not installed, so not removed 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 

That is the message you’ll receive if you attempt to remove a package that doesn’t exist. The following is an example of a successful uninstall:

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

Package Cleanup

If you find that your disk space decreases without explanation, it might be related to your use ofapt-get. When you install software, the packages download to your local disk’s cache directory. You can use apt-get to perform the necessary housekeeping functions for you. Running the cleanoption can free up a significant amount of space for you. If you want to look at the list of packages in the apt-get queue, they’re in the /var/cache/apt/archives directory.

debian:/etc/apt# df -h Filesystem            Size  Used Avail Use% Mounted on /dev/sda1             4.7G  3.4G  1.1G  76% / tmpfs                 253M     0  253M   0% /lib/init/rw udev                   10M  588K  9.5M   6% /dev tmpfs                 253M     0  253M   0% /dev/shm /dev/sda2             5.0G  1.6G  3.1G  35% /var  debian:/etc/apt# apt-get clean  debian:/etc/apt# df -h Filesystem            Size  Used Avail Use% Mounted on /dev/sda1             4.7G  3.4G  1.1G  76% / tmpfs                 253M     0  253M   0% /lib/init/rw udev                   10M  588K  9.5M   6% /dev tmpfs                 253M     0  253M   0% /dev/shm /dev/sda2             5.0G  380M  4.4G   8% /var 

You can see from the clean process that the /var directory is now relatively empty. Performing this housekeeping function on a regular basis is something you should do on a regular basis to free valuable disk space.

A Helping Hand

If you’ve never needed help on a Linux system, consider yourself alone in a world of needy users and system administrators who do. Manual (man) pages are your primary source of extended information and documentation for commands and utilities. Currently, the man page for apt-get is over 400 lines long and has in-depth information on almost every aspect of the utility.

If you’re like most people, you only need a slight “refresher” to nudge you in the right direction and not a book length treatise on the subject. Well documented utilities like apt-get have additional online help available to you that displays an abbreviated man page that just hits the most popular command options and switches.

Try the online help for apt-get by typing:

$ apt-get help  apt 0.7.20.2 for i386 compiled on Apr 20 2009 21:52:39 Usage: apt-get [options] command        apt-get [options] install|remove pkg1 [pkg2 ...]        apt-get [options] source pkg1 [pkg2 ...]  apt-get is a simple command line interface for downloading and installing packages. The most frequently used commands are update and install.  Commands:    update - Retrieve new lists of packages    upgrade - Perform an upgrade    install - Install new packages (pkg is libc6 not libc6.deb)    remove - Remove packages    autoremove - Remove automatically all unused packages    purge - Remove and purge packages    source - Download source archives    build-dep - Configure build-dependencies for source packages    dist-upgrade - Distribution upgrade, see apt-get(8)    dselect-upgrade - Follow dselect selections    clean - Erase downloaded archive files    autoclean - Erase old downloaded archive files    check - Verify that there are no broken dependencies  Options:   -h  This help text.   -q  Loggable output - no progress indicator   -qq No output except for errors   -d  Download only - do NOT install or unpack archives   -s  No-act. Perform ordering simulation   -y  Assume Yes to all queries and do not prompt   -f  Attempt to correct a system with broken dependencies in place   -m  Attempt to continue if archives are unlocatable   -u  Show a list of upgraded packages as well   -b  Build the source package after fetching it   -V  Show verbose version numbers   -c=? Read this configuration file   -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp See the apt-get(8), sources.list(5) and apt.conf(5) manual pages for more information and options.                        This APT has Super Cow Powers. 

The online help, as you can see, gives you almost everything you need without paging through 400+ lines of man page.

In The Moo’d

If you’re in the moo’d for something completely different, you’ll notice at the end of the apt-gethelp, the line, “This APT has Super Cow Powers.” Try this:

$ apt-get moo           (__)          (oo)    /------/   / |    ||  *  /---/     ~~   ~~ ...."Have you mooed today?"... 

You’re welcome.

Next week, in Part Two, I’ll introduce you to Aptitude, which is a more user friendly version of apt-get.

There was an error in this gadget
There was an error in this gadget