Debian Package Management, Part 1: A User's Guide
APT stands for “Advanced Package Tool”. It does a wonderful job of simplifying the life of a Debian user. If the last session discouraged you, fear not! APT is what I use for most of my package management. Why then, you ask, did I force dpkg on you? Because it's important to know what is underneath APT.
The APT system consists of three major parts: the configuration file, sources.list, and two programs called apt-get and apt-cache. There also are some minor parts, like apt-cdrom.
Once you learn how to use it, /etc/apt/sources.list will become one of the most important files in your system. For the most part, sources.list consists of ftp and http addresses where APT can go to pull information, and is a great way to organize your resources in one location. A typical entry looks something like:
deb http://http.us.debian.org/debian unstablemain contrib non-free
The first part of the entry is either “deb”, for a line that specifies where to acquire binaries from, or “deb-src” which specifies where to acquire debian source packages. The next part is called a URI, which is similar to a URL; this is the root of the debian directory. After the URI comes the distribution, which is generally listed as “stable”, “frozen” or “unstable”, although a specific distribution, like Hamm, Slink or Potato, can be used. Distribution can also be given as an exact path, in which case it needs to end with a “/”, and no components can be specified. Components are usually “main”, “contrib”, “non-free”, “non-us/main”, “non-us/contrib” or “non-us/non-Free”. That's about all you need to know to take advantage of sources.list. CD-ROM entries are generated by apt-cdrom (more on this later), so you don't need to write those by hand.
Editing the source.list file is done to change the sites APT uses (changing mirrors), to change which distribution APT will be getting packages from, or simply to add new URIs for “unofficial” debs, or sites which maintain newer debs, like KDE and HelixCode, respectively. After editing this file, you should always run apt-get update. For a listing of Debian mirrors to use, check http://www.debian.org/.
One way to add your Debian CD-ROMs to APT's database is with the remarkably easy-to-use apt-cdrom. The command apt-cdrom add should automatically mount your CD-ROM (provided /dev/cdrom is correctly linked), scan it and create the correct entry in /etc/apt/sources.list.
As with anything in Linux, that's not the only way to do it! If your Debian CD-ROM is mounted (the mount point must be listed in /etc/fstab), you can use a few flags to accomplish the task. Use -d <mount point> to specify the mount point,-f to make apt-cdrom not check the individual packages, and -a for a thorough package scan that will look for package files everywhere on the CD-ROM.
Debian's greatest claim to fame is apt-get, an incredibly smart (okay, smart most of the time), easy-to-use package tool that automatically deals with package dependencies and conflicts. The first thing you should do (and do it every time you edit /etc/apt/sources.list) is run apt-get update, which pulls the package information used by apt-cache and apt-get from these locations.
Now, you can go about installing packages. APT's most used action is probably install. To install a new package (and automatically meet its dependencies), use apt-get install <package>. If there are other packages that must be installed, APT will let you know before downloading them.
If you install a deb without meeting the requirements, or a problem is encountered during install or removal, you will often be unable to work with dpkg until the problem is resolved. One method to use for solving these problems is the command apt-get -f install, which will try to work everything out and ask questions as it goes along.
APT can also download sources with apt-get source <package> if you have any deb-src lines in your /etc/apt/sources.list. To remove packages, use apt-get remove <package>. If you want to clean out the archives, there are two options. To remove all archives, the command is apt-get clean; if you only want to remove old archives, use apt-get autoclean instead. When the time comes to upgrade all packages to their latest version, one easy command, apt-get upgrade, will take care of it. Meanwhile, apt-get dist-upgrade is suited for upgrading to a new version of Debian, automatically reconfiguring dependencies for packages whose names have changed.
A few other command-line options are helpful when using apt-get: “-d” only downloads archives but doesn't try to install or unpack them; “-s” for simulation, it won't actually do anything; “y” answers yes to all questions; and “-b” tries to build a source package after downloading it.
Additionally, apt-get can use regular expression patterns such as apt-get install '.*mame.*' or apt-get remove 'mozill.'. Apt-get will also try to match an element appearing at a specific point in the string. For example, to match “pilot” only in the beginning position, like “pilot-manager” and not “gnome-pilot”, use “^” (which is the “beginning of line” character) in an expression like apt-get install '^pilot.*'.
- Smoothwall Express
- Machine Learning Everywhere
- Own Your DNS Data
- Bash Shell Script: Building a Better March Madness Bracket
- Simple Server Hardening
- From vs. to + for Microsoft and Linux
- Understanding OpenStack's Success
- Returning Values from Bash Functions
- Understanding Firewalld in Multi-Zone Configurations
- The Weather Outside Is Frightful (Or Is It?)