Introduction to APT (advanced package Tools)

Advanced Packaging Tool

Ubuntu — and all Debian-based distros — includes the Advanced Packaging Tool (APT), which can be used to easily download and install software for the operating system. This article looks at APT, and how it is used.

Topics :
Table of Contents
Installing Software on a Computer
Installing Software on Windows
Installing Software on Linux
Repositories
Enabling Additional Repositories
Software Updates
Configuring Package Updates
GUI Front-Ends to APT
Add/Remove Programs
Synaptic Package Manager
Using APT from the Command-Line
apt-get
dpkg
wget
apt-cache

Installing Software on a Computer

While some software consists of a single, executable file, that runs on its own, most software is more complex than that. Along with the executable file(s), there may be data files, configuration files, libraries (which may also be shareable with other applications), and, usually dependencies. A dependency isanother program, that this program needs to do its work. For example, if I write a plugin that will work in the Firefox web browser, then of course my plugin would need Firefox, before it would run — Firefox would be a dependency. Or if I write a program that has the ability to update itself from the internet, it might depend on a web browser being installed, which it can use for the HTTP access.

This means that there are numerous things you have to do, to make a program run on someone’s computer; you have to:

  • Compile the “source code” into an executable program
  • Copy the executable file(s) to the appropriate target destination(s); in Windows, this might mean copying the files to a subdirectory of theC:\Program Files directory.
  • Copy over any applicable configuration files — and, possibly, set some of those configurations, for the specific user/machine
  • Copy over any applicable data files
  • For Windows machines, there would likely also be changes that need to be made to the system’s registry

Installing Software on Windows

In the Windows world, this would all be done by a setup program. This is an executable file, which has, packaged within it, all of the files that need to be installed on a computer, and instructions on how to set it up — how to edit the registry, copy the appropriate files to the appropriate locations, check for dependencies, etc. Some setup programs might even ask the user various questions, as it runs, to get information about the computer on which it will be running, or the user’s preferences on how some aspects of the software should work.

The setup program is also responsible for letting Windows know what it has done, and what has to be done to uninstall the program, in case the user ever needs to remove it. Some of these setup programs work very well, and some don’t.

Installing Software on Linux

In Linux, things can be a bit more complex — or they can be even easier!

In the early days of Linux, the only way to get a piece of software running on your machine was to download the source code, and compile it yourself. (If the software has dependencies, it should be caught when the code is compiling.) This made a lot of sense, because much of the software that runs on Linux is open source anyway — they’re already giving you the source code, so just go ahead and compile it! It also puts the user in total control over the installation process, which is a very Linux-like thing to do.

Downloading and compiling the source is still a valid way to get much of the software available for Linux. However, there are some easier methods, too. For example, some developers will compile the code for you, and make the binary files available. If you decide to download a binary, however, you’ll have to make sure that you download an appropriate version — software compiled for Red Hat won’t necessarily work on Ubuntu, or vice versa. And, of course, if there is more than one file needed for the software to run, you’ll need to make sure you download all of the necessary pieces: binaries, configuration files, etc.

Some developers will take things a step further, and create self-installing binaries. These self-installing binaries are very similar to Windows setup programs; most even include a UI, which will walk you through the setup process. In fact, anyone who is familiar with the wizard-style interface used by Windows setup programs will be instantly at home using a self-installing binary.

But the easiest way to install software is with a package. A package is designed to work with a package manager — software that runs on a user’s machine, and keeps track of which packages have been installed, what versions have been installed, and which packages have dependencies on which other packages. The package file contains the file(s) needed for the program, including the executable files(s), along with configuration information for the package manager, to know how to install the program.

If you tell a package manager that you’d like to install a particular package, it can tell you what other packages are dependencies, and, if requested, automatically download and install them for you, before getting to the package you were after in the first place. Similarly, if you tell a package manager to remove a particular package, it will check first to make sure that there are no other packages dependent on it. The Advanced Packaging Tool (APT) is the package manager used in Ubuntu.

A package made for APT can be recognized because it has a .deb extension. Packages created for other package managers would have different extensions.

The rest of this article will discuss APT; how it works, and how to use it. But first, we have to look at repositories, because APT, like any other package management software, needs a repository from which it can get packages.

Repositories

repository is a database of available packages, that can be downloaded by your package manager. The repository is maintained centrally, but individual computers keep a cached list of the packages available in the repository — and, therefore, need to occasionally go back to the repository to get an updated list. So when you use APT to find out what packages are available to you (usually through Add/Remove Programs or Synaptic Package Manager, although you can also use apt-cache), you’re actually looking at the locally cached version of the central Ubuntu repositories.

There are actually a number of repositories available, for Ubuntu:

  • Main — this is software which is “officially supported” by the Ubuntu team.
  • Restricted — this software is supported, but doesn’t fully follow the “free software philosophy.” In other words, the software isn’t available under a completely free license.
  • Universe — this is software which is community-maintained, rather than “officially supported” by the Ubuntu team. It doesn’t mean the software is any more buggy than the Main software, it just means that the Ubuntu team won’t provide direct support for it1. The software is free, however, just like the software in the Main repository.
  • Multiverse — this is software that’s not free, and not supported by the Ubuntu team. It doesn’t mean you shouldn’t or can’t use it, you just have to put more thought into it before downloading it, especially in regards to licensing issues. (For an example of this, see the Setting Up Audio/Video Codecs page.)

Ubuntu will not use some of these repositories unless you specifically enable it to, because of the licensing and support issues. However, enabling them is very easy.

Enabling Additional Repositories

As mentioned, you will only have access to certain repositories, by default, when you first install Ubuntu. But you can enable access to other repositories, in the Synaptic Package Manager.

To do so, follow these steps:

repositories.png
  1. Open Synaptic Package Manager, at System->Administration->Synaptic Package Manager. (You will be asked for your password.)
  2. Go to the Settings->Repositories menu, which will bring up a dialog, similar to the one pictured at the right.
  3. This dialog changes, from version to version of Ubuntu, but you want to look for a tab which lists the different repositories that APT will use; at the time I wrote this article, when I was on Edgy Eft, it was in the Ubuntu 6.10tab, in the Internet section.
  4. You will see, in this dialog, that there are various options for repositories I can use from the Internet. There are “user-friendly” names, followed in parentheses by the repository categories listed above: main, restricted, universe, and multiverse. Simply checking the checkbox for any repository will enable Ubuntu to use it.

When you have followed these steps, you’ll have to close Synaptic Package Manager for the changes to take effect, and possibly even restart Ubuntu2.

Software Updates

Because of the package management tools available, installing software under Ubuntu is very easy. Tell APT to get the appropriate package, and it will not only do so for you, but also get any packages that your package depends on. Nothing could be simpler!

But there is another benefit to the central repository concept: Ubuntu can get updates much more easily, for operating system components, or even for other software installed on the system. On a regular basis — once a day, by default — APT will look for updates to any installed software on the system. If there are any available, you will be notified, and can decide whether you want the update or not. When updates are available, a little icon will appear in your notification tray updatestar.png, along with a pop-up message indicating that new updates are available. If you click the icon, you’ll be given a list of the available updates, and can check off the ones you want to install.

updatesavailable.png

You can configure how often Ubuntu will look for updates, and what to do when they are available, in the Synaptic Package Manager.

Configuring Package Updates

If you want to change the way Ubuntu handles updates to packages in your repositories, simply follow these steps:

updates.png
  1. Open Synaptic Package Manager, at System->Administration->Synaptic Package Manager. (You will be asked for your password.)
  2. Go to the Settings->Repositories menu, which will bring up a dialog.
  3. Go to the Internet Updates tab, which is pictured to the right. Here you will be given various options, as to what types of updates Ubuntu should look for, and what to do when they are available.
    • Types of updates:
      • Security Updates — these updates are critical to keep your system safe from malicious attackers. This should always be enabled, and if you’re prompted to install these updates, you should do so!
      • Recommended Updates — these updates are not as critical as the Security updates, but they’re still important to have, for the stable running of Ubuntu.
      • Proposed Updates — these updates are not yet finalized, by the developers. If you’re having problems with a particular program, you might want to enable these updates, to get the latest and [potentially] greatest updates, but otherwise, you probably wouldn’t want to select this option.
      • Backported Updates — I haven’t the faintest idea what these updates are!
    • How to handle updates:
      • You can select how often Ubuntu should check for updates. The default is “daily,” but you can also choose “every two days,” “weekly,” or “every two weeks.”
      • Once Ubuntu has found an update, it can do various things: the default is to simply notify you that the update is available, and ask you what you want to do; it can also download updates automatically, in the background, and then ask you if you want to install them; finally, if you wish, Ubuntu can automatically download and install any updates automatically, without ever telling you.

GUI Front-Ends to APT

APT is based on the Debian package manager. It can be used from the command line, but there are also two GUI-based front-ends for APT:Add/Remove Programs, which can be found at the bottom of Ubuntu’s application menu, and the Synaptic Package Manager, which can be found in the System->Administration->Synaptic Package Manager menu.

Add/Remove Programs

AddRemoveApplications.png

Both applications do similar things, but the Add/Remove Programs application is a quicker and easier way to install software. (Windows users will surely find the Add/Remove Programs application more intuitive.) You don’t need to know anything about package names, or dependencies, to use it; simply use the GUI interface to find — or search for — the program you’re looking for. Click the checkbox, and APT will be called in the background, to install the necessary package(s) to make the application run.

Applications listed in the Add/Remove Programs application use intuitive names, rather than their package names. For example, suppose the only instant messaging service you use is MSN Messenger, and therefore decide that you’d rather use aMSN than Gaim. The package name for aMSN will be something similar to this: amsn_0.94-1_i386.deb. However, if you look in the Add/Remove Programs application, it will simply be listed as aMSN. You don’t need to know the version of the application; Add/Remove Programs will simply get you the latest one, available in APT’s repository. You don’t need to worry about the i386 part — all of the packages available to you on Ubuntu will be for i386 machines.

Removing applications is just as easy. Open Add/Remove Programs, find the application you want to remove, and un-check its checkbox. It will either be removed, or Add/Remove Programs will tell you it can’t be removed, if other applications are dependent on it.

Synaptic Package Manager

SynapticPackageManager.png

The Synaptic Package Manager is more detailed than the Add/Remove Programs application. It shows each and every package available in its repository, whether it’s a top-level package representing an entire application, or a smaller piece of a larger application. However, the technique for using the Synaptic Package Manager is the same: you choose a package, tell the Synaptic Package Manager that you want to install it, and it will take care of making sure that all of your dependencies are also installed.

There is also some extra functionality available in Synaptic Package Manager, that you can’t do from Add/Remove Programs. For example, you can refresh the package list from the repositories, and even change which repositories APT will use, to look for updated packages.

The Synaptic Package Manager also requires you to enter your administrator password, which the Add/Remove Programs application does not. (Or at least, it doesn’t always…)

Using APT from the Command-Line

If you’re following instructions on the web for installing a piece of software for Ubuntu, it’s almost guaranteed that the instructions given will be for using APT from the command-line, rather than using Add/Remove Programs or the Synaptic Package Manager. Linux nerds simply won’t give up their command-line mentality — which is both good and bad, but outside the scope of this article.

So this section will give you some information on the common commands you’ll see, and what they mean. So, when you see a web page somewhere that tells you to enter the following command:

<code>$ sudo apt-get install libdvdcss2</code>

you’ll know exactly what’s going on.

There are a few commands discussed in this section, each of which has various parameters:

  • apt-get
  • dpkg
  • wget
  • apt-cache

I’m not putting each and every parameter on this page; just the most common ones. Most of these commands will have to be prefaced with the sudocommand, since you need to be an administrator to do many installation / uninstallation activities.

apt-get

The apt-get command is the one you’ll use most, when working with APT. It is used to install, or uninstall, a package on your system.

The syntax for using the command will be one of the following:

<code>$ sudo apt-get install PACKAGENAME $ sudo apt-get remove PACKAGENAME $ sudo apt-get update $ sudo apt-get clean $ sudo apt-get dist-upgrade</code>

The most common option is the “install” option. This will install the referenced package — along with any dependent packages — from the repository. For example, the example given earlier was

<code>$ sudo apt-get install libdvdcss2</code>

This would install the libdvdcss2 package on your system, along with any packages that libdvdcss2 depends on. Notice that you don’t need to include the “full” package name, including the version number, the i386 part, and the .deb extension; APT will simply get the latest version of the package which applies to your system.

As you might have assumed, the “remove” option does the opposite of “install,” and removes a package.

The “update” option instructs APT to go back to the repository, and revise its local cached list of available software packages.

The “clean” option is used to remove any old packages that have been downloaded to your hard disk. Once a package has been downloaded and installed, the actual package file isn’t really necessary anymore, so you can run apt-get with the “clean” parameter from time to time, to remove any packages that have been downloaded.

The “dist-upgrade” option can be used to upgrade the entire Ubuntu operating system, when a new release is issued. I’ve heard mixed reports about usingapt-get to upgrade Ubuntu, and the one time that I tried it, it didn’t work. So you can decide whether you want to use this or not.

dpkg

The dpkg command is used for installing a package file, which has been manually downloaded. (Behind the scenes, dpkg is used by apt-get.) You don’t normally need to use dpkg, because you don’t normally download packages manually. However, if you do, dpkg is what you want.

If you need to use dpkg be aware that it will warn you about dependency issues — meaning that the package depends on another package, which isn’t installed on your system — but it will not halt execution, or go and get the dependent packages. So if you use dpkg and get one of these warnings, you should find and install the package you were warned about, or your newly installed package will not work correctly.

The syntax you use for dpkg will be one of the following:

<code>$ sudo dpkg -i FULLPACKAGENAME $ sudo dpkg -r FULLPACKAGENAME $ sudo dpkg -I FULLPACKAGENAME</code>

The -i parameter is used for installing a package, whereas the -r parameter is used to uninstall a package which was previously installed. The -Iparameter is used to get information about a package.

Note that dpkg requires the full name of the package file, not it’s “friendly name.” For example, if I were to manually download the package for aMSN, the package name would be something like amsn_0.94-1_i386.deb and this is what I would have to use to install it, using dpkg, like this:

<code>$ sudo dpkg -i amsn_0.94-1_i386.deb</code>

However, you can use the Tab key, within BASH, to save yourself some typing; e.g. if you type in

<code>$ sudo dpkg -i amsn</code>

and then hit Tab, BASH will probably have enough information to fill in the rest of the filename for you.

wget

If you’re using dpkg to install a package, you need to have the package file on your computer. You might have done this by downloading it from a site on the internet, using your web browser of choice, or you might get it using the wget command. There are some options for wget, but you don’t normally need to use them, so you can just supply the URL of the file you’re downloading:

<code>$ wget URL</code>

If you want to download the Flash plugin, at one time the URL was http://www.adobe.com/go/fp9_update_b1_installer_linuxplugin — so you would simply pass that URL to wget like this:

<code>$ wget http://www.adobe.com/go/fp9_update_b1_installer_linuxplugin --15:41:40-- http://www.adobe.com/go/fp9_update_b1_installer_linuxplugin =&gt; `fp9_update_b1_installer_linuxplugin' Resolving www.adobe.com... 192.150.18.60 Connecting to www.adobe.com|192.150.18.60|:80... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: http://labs.adobe.com/technologies/flashplayer9/ [following] --15:41:41-- http://labs.adobe.com/technologies/flashplayer9/ =&gt; `index.html' Resolving labs.adobe.com... 216.104.212.161 Connecting to labs.adobe.com|216.104.212.161|:80... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [text/html] [ &lt;=&gt; ] 25,295 89.52K/s 15:41:41 (89.51 KB/s) - `index.html' saved [25295]</code>

As shown, while the wget command is running, you’ll see various things fly by your screen, including a status indicator, to tell you how far the download has proceeded. (In this case, I got a message that the URL was no longer correct, and wget was redirected to a new URL.)

This is actually a pretty nonsensical example; what I ended up downloading with this command was a file calledindex.html — in other words, the default web page at the flash player download site, instead of the package file.

Normally, wget is used when you want to download and install a particular package. So you’ll often see instructions on the internet that are similar to the following:

<code>$ wget http://somewhere.com/downloads/packagename.deb $ sudo dpkg -i packagename.deb</code>

apt-cache

The apt-cache command can be used to get information about particular packages, from the cached repository information on your computer. There syntax you use will be one of the following:

<code>$ apt-cache search SEARCHTERM $ apt-cache showpkg SEARCHTERM $ apt-cache depends SEARCHTERM</code>

Note that this command is just informational; it simply returns information about packages. So it doesn’t need to be prefaced with sudo.

The “search” parameter will look in the cached repository for packages that match your search term. For example, if I do a search for “amsn,” I might get back the following:

<code>$ apt-cache search amsn amsn - An MSN messenger written in tcl</code>

This gives me the package, and a description of the package. If I want further information about that package, I would do the following:

<code>$ apt-cache showpkg amsn Package: amsn Versions: 0.95-2.1 (/var/lib/apt/lists/ca.archive.ubuntu.com_ubuntu_dists_edgy_universe_binary-i386_Packages) Description Language: File: /var/lib/apt/lists/ca.archive.ubuntu.com_ubuntu_dists_edgy_universe_binary-i386_Packages MD5: b84c33e6fc6457fc6c66b00090ae282d Reverse Depends: Dependencies: 0.95-2.1 - imlib11 (0 (null)) tcl8.4 (0 (null)) sox (0 (null)) tk8.4 (0 (null)) libpng12-0 (0 (null)) docker (0 (null)) tcltls (0 (null)) python (0 (null)) libc6 (2 2.4-1) libgcc1 (2 1:4.1.1-12) libice6 (0 (null)) libsm6 (0 (null)) libstdc++6 (2 4.1.1-12) libx11-6 (0 (null)) mozilla (16 (null)) galeon (16 (null)) konqueror (0 (null)) imagemagick (0 (null)) ccmsn (0 (null)) Provides: 0.95-2.1 - Reverse Provides:</code>

As you can see, there’s a lot of information there!

And finally, if I just want to see the package’s dependencies, I can do this:

<code>$ apt-cache depends amsn amsn Depends: imlib11 Depends: tcl8.4 Depends: sox Depends: tk8.4 Depends: libpng12-0 Depends: docker Depends: tcltls Depends: python Depends: libc6 Depends: libgcc1 Depends: libice6 Depends: libsm6 Depends: libstdc++6 Depends: libx11-6 |Suggests: mozilla |Suggests: galeon Suggests: konqueror Suggests: imagemagick graphicsmagick-imagemagick-compat Replaces: &lt;ccmsn&gt;</code>

Leave a Reply

Your email address will not be published. Required fields are marked *