Apt-get Guide

From Linuxhelp Wiki

Author:Corey
Created On:February 1st, 2005
Updated On:June 14th, 2005

Contents

Introduction

The Debian package management system is one of the best out there. It includes dependency resolution, easy installs, availability and organization. While the deb package system is not the most popular for distributions, it is very popular amongst its users. Debian uses apt-get for handling packages.

Configuration

First, to configure your system, you need to setup your sources.list file which is located in /etc/apt/sources.list . This file contains the information that apt looks for when attempting to install a package. Sources can include a cdrom, ftp, http, nfs, etc. One of the benefits of Debian is that you do not need a cd to install or maintain a system, you can configure it to work totally from the internet. The following is an example sources.list file for the main stable distribution:

Note: Editing apt-get config files as well as issuing apt-get commands must be done as root or with sudo.

# /etc/sources.list - APT repositories
#
deb ftp://ftp.us.debian.org/debian stable main contrib non-free
deb-src ftp://ftp.us.debian.org/debian stable main contrib non-free

# The following line is for security updates released by Debian
deb http://security.debian.org/ stable/updates main

You can add any repository that you like, a good list of third-party sources is available on http://www.apt-get.org.

Syncking with Repository

After saving your sources.list file, we first want to update our local database so that it's in sync with Debian's sources:

apt-get update

The output will show apt-get downloading the information from Debian's servers and then syncking its own database. Your output should look something like this:


linuxhelp.net:~# apt-get update
Get:1 ftp://ftp.debian.org testing/main Packages [3245kB]
Get:2 http://security.debian.org stable/updates/main Packages [220kB]
Get:3 http://security.debian.org stable/updates/main Release [110B]
Get:4 ftp://ftp.debian.org testing/main Release [81B]
Get:5 ftp://ftp.debian.org testing/main Sources [1280kB]
Get:6 ftp://ftp.debian.org testing/main Release [83B]
Fetched 4744kB in 2m40s (29.5kB/s)
Reading Package Lists... Done
linuxhelp.net:~#

Package Installation

From here we can install any piece of software available on the Debian servers with a simple, one-line command. For example, if we wanted to install Mozilla Firefox, you would issue the following command:

linuxhelp.net:~# apt-get install mozilla-firefox

From here, apt will look at its database and see if the package is available. If it is, it then checks to see what mozilla-firefox depends on, then queues those dependencies to download along with the package. Here is the output when I attempted this on my Debian system:

linuxhelp.net:~# apt-get install mozilla-firefox
Reading Package Lists... Done
Building Dependency Tree... Done
The following extra packages will be installed:
  libatk1.0-0 libgtk2.0-0 libgtk2.0-bin libgtk2.0-common libidl0 libpango1.0-0
  libpango1.0-common libxcursor1 libxft2
Suggested packages:
  ttf-kochi-gothic ttf-kochi-mincho ttf-thryomanes ttf-baekmuk
  ttf-arphic-gbsn00lp ttf-arphic-bsmi00lp ttf-arphic-gkai00mp
  ttf-arphic-bkai00mp mozilla-firefox-gnome-support latex-xft-fonts
  xprt-xprintorg
Recommended packages:
  libatk1.0-data x-ttcidfont-conf
The following NEW packages will be installed:
  libatk1.0-0 libgtk2.0-0 libgtk2.0-bin libgtk2.0-common libidl0 libpango1.0-0
  libpango1.0-common libxcursor1 libxft2 mozilla-firefox
0 upgraded, 10 newly installed, 0 to remove and 7 not upgraded.
Need to get 14.9MB of archives.
After unpacking 43.1MB of additional disk space will be used.
Do you want to continue? [Y/n]

There are a few things that you should notice about the above output, so I will step through them individually. First off, apt checks its database for the package, and then resolves what dependencies are needed. Then you see a line that states "The following extra packages will be installed", these are the packages that must be installed in order for Firefox to install.

Below this we have "Suggested packages" which are additional packages that were suggested by the Firefox package maintainer that will go nicely with Firefox, These don't have to be installed, but installing them will make your experience with Firefox better.

Next we have "Recommended packages", which is very similar to Suggested packages, but may provide more crucial functionality to Firefox. Please note, though, that "recommended" and "suggested" packages are not queues to download and install by default; you will have to take it upon yourself to install these packages when Firefox completes.

Next, apt tells us what NEW packages will be installed, which includes the original package 'mozilla-firefox' as well as all the dependencies.

The next line tells us how many packages will be upgraded, how many packages will be newly installed, how many packages will be removed and how many packages will not be upgraded. If we previously had Firefox installed, but the version installed was earlier than the version available on the server, apt will download the updated version and install. If we issued a command that required an installed package to be removed, then that will be listed there as well. In my example, above, it shows that 7 packages are not upgrade. What that means is that since the last time I syncked my local apt database with Debian's, 7 of my installed packages have available upgrades on the server that I have yet to install. This can be taken care of later.

Finally, apt tells us how many MB's it needs to download, and how much space the packages will use up on our file system and then asks us if we want to proceed. If there was something along the way that you didn't quite expect to happen, you can say "no" at the prompt and start over. Remember when issuing an apt-get command that you should check what apt is going to do before you say "yes", or you could end up deleting a lot of packages that you didn't intend on doing.

After saying Yes, you will see the output of apt as it downloads your packages and installs them. During the install process, you may be presented with a series of questions about how you want your software to be configured. You should take the time to read each screen to ensure that everything is set up the way you want it. Debian package maintainers usually keep a good set of defaults to ensure everything works properly "out-of-the-box".

Upgrading your System

There are two types of upgrades with apt-get, package upgrades and distribution upgrades.

Package Upgrades

Before working with apt, you should always ensure that your local database is in the sync with the servers by issuing:

apt-get update

Sometimes over a period of time (and even more frequently if you're using the testing or unstable tree), newer versions of packages appear on the Debian servers. Sometimes they can include new features, bug fixes or even more importantly, security fixes. Because of this, you should always try and keep your system as up-to-date as possible. Personally, I check daily to ensure that all my packages are up-to-date. To upgrade any packages on your system with new versions available through apt, issue the following command:

apt-get upgrade

You should see some output like the following:

linuxhelp.net:~# apt-get upgrade
Reading Package Lists... Done
Building Dependency Tree... Done
The following packages will be upgraded:
  centericq centericq-common login module-init-tools passwd postfix
  postfix-tls
7 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 3776kB of archives.
After unpacking 112kB of additional disk space will be used.
Do you want to continue? [Y/n]

The output is similar to that of the install command, however, it lists the 7 packages that need upgrading on my system. After saying "Yes", apt will download the updated packages and proceed to install them. If there are any packages that have changes in configuration files, apt will prompt you for what action to take. If you read everything on screen, you should understand what to do.

Debian "trees"

Stable tree

The "stable" tree is the currently supported official release, this is usually denoted with a name, and version number. For example, as of this writing, the current "stable" tree is called "Sarge" and is given the version number "3.1". If you are running a system that requires security, stability and reliability, this tree is the best way to go. The other trees may work just as well, but the "Stable" release is tried, tested and true. Debian puts a lot of time and effort into their releases with a development cycle that sometimes spans 2 years or more. Chances are, if you run the stable release, you will never run into a problem with packages at all.

Testing tree

The "testing" tree is the name given to Debian's next release. While the "stable" tree is trusty and reliable, it can sometimes be out-dated due to the long development cycle, this is where "testing" comes into play. This tree is also given a name, however, it's actual version is not denoted until it's deemed stable and is officially released to the public. As of this writing, the current testing tree is called "Etch" and is currently in early testing. When it is released, it could be version 3.2, 4.0 or even 7.0, we won't know until it's released. Many desktop Debian users will use the testing tree because it provides more up-to-date software, however, it is not as stable as the stable tree and sometimes there will be quirks.

Unstable tree

The "unstable" tree is the name given to Debian's development release that is still in heavy development. When new packages are created, they are usually entered into the "unstable" tree for heavy testing before it's moved into the "testing" tree. Like the other trees, the "unstable" has a nickname of "Sid" which stands for "Still In Development" (as well as the kid named Sid in "Toy Story"). The unstable tree is, as it states, pretty unstable. While some users can use it for a while and never see a problem, others will run into major roadblocks with conflicts and missing dependencies. The unstable tree, or "Sid," will never be an official release, therefore, it has no version, and never will; it is basically a 'sandbox' of development.

Upgrading your Distribution

This is a very powerful concept that many distributions have been struggling with for years. Debian provides a very simple method of upgrading your distribution to the newest release.

If you are running the stable tree and Debian releases a new version, for example, in the next couple of months, Debian will be moving from "Woody" to "Sarge", so there will be a new stable tree. If you are currently running Woody, then you can easily upgrade to the new Sarge by issuing the following commands:

linuxhelp:~# apt-get update
linuxhelp:~# apt-get dist-upgrade

This will upgrade your distribution to the newest release, as well as all the packages available.

Now, what if you are running "Sarge" (or 'stable'), and you decide that for whatever reason, you want to upgrade to the "testing" tree? Luckily, this is easy to accomplish. Once again, we go back to our sources.list file and make a few modifications.

Important: It is very important to note that while you can move from Stable to Testing, or Testing to Unstable, you cannot move backwards. Once you go to Testing, you cannot go back to Stable or from Unstable to testing without a lot of effort. So, once you do this, you can't go back.

This was our original sources.list file:

# /etc/sources.list - APT repositories
#
deb ftp://ftp.us.debian.org/debian stable main contrib non-free
deb-src ftp://ftp.us.debian.org/debian stable main contrib non-free

# The following line is for security updates released by Debian
deb http://security.debian.org/ stable/updates main

All we need to do, is to take the references of "stable" and change them to "testing":

# /etc/sources.list - APT repositories
#
deb ftp://ftp.us.debian.org/debian testing main contrib non-free
deb-src ftp://ftp.us.debian.org/debian testing main contrib non-free

# The following line is for security updates released by Debian
# deb http://security.debian.org/ stable/updates main

You may notice that I commented out the line (placed a # in front of it) for the security updates. This is because Debian only provides a repository of security updates for the stable tree. For the testing tree, security updates are integrated directly into the repository itself, so whenever you do an apt-get upgrade in the future, they will be included.

After editing your sources.list file, you can go ahead and execute the dist-upgrade command:

linuxhelp.net:~# apt-get dist-upgrade

This will upgrade your distribution to the "testing" tree.

apt-get Commands

There are a number of other commands for apt-get, I will run through a few of them here:

linuxhelp.net:~# apt-get --help
apt 0.5.28.1 for linux i386 compiled on Jan 10 2005 14:25:31
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
   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 continue if the integrity check fails
  -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 arbitary 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.

Install

As stated earlier, this installs a package:

apt-get install mozilla-firefox

Upgrade

Upgrades your currently installed packages to the latest releases available in your Debian tree

apt-get upgrade

Update

Updates your local apt database so that it is in sync with the sources defined in your sources.list file.

apt-get update

Remove

Removes a package from your system, if other packages depends on the stated package, apt will prompt you with what packages will be affected. By default, apt will not remove configuration files, if you would like them to be removed as well, please see below:

apt-get remove mozilla-firefox

To remove all configuraiton files from a package, you need to pass along a switch:

apt-get --purge remove mozilla-firefox

Source

Downloads the source code to the stated package and allows you to make modifications for your own system.

apt-get source mozilla-firefox

Build-dep

If you want to build a package from a source retrieved in the previous command, you will need it's build dependancies. This command will check with the source file and download/install the dependencies needed to compile it:

apt-get build-dep mozilla-firefox

Dist-upgrade

Executes a distribution upgrade as state in an earlier section

apt-get dist-upgrade

dselect-upgrade

This command upgrades the packages as stated in dselect.

apt-get dselect-upgrade

clean and autoclean

This command cleans out the local archive of downloaded files, this is usually a safe thing to do. However, if you are a dial-up user, you may want to keep the packages on your system in cases where you may need to uninstall and re-install a package.

apt-get clean && apt-get autoclean

Check

Verifies that there are no broken dependencies with installed packages. This is a useful command to perform periodically.

apt-get Options

There are a few options available through apt that will manipulate the way it performs:

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 continue if the integrity check fails
 -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 arbitary configuration option, eg -o dir::cache=/tmp

Conclusion

This guide ended up being much longer than I first anticipated, but it's no wonder. Apt-get is a very powerful tool that has been in development for many years. Once you get used to it, you won't know how you ever got along with out it before.

What's Related

  • dpkg - The Debian package manager
  • dselect - The deb frontend
  • apt-rpm - A version of apt-get for RPM-based Distributions