Working on the Command Line


With so much software available for install, it is no surprise that Debian-based distros have many ways to manage software installation. At their root, however, they all use Debian's world-renowned Advanced Package Tool. One poster on Slashdot once said, "Welcome to Slashdot. If you can't think of anything original, just say how much APT rocks and you'll fit right in." You see, even though many other distros have tried to equal the power of APT, nothing else even comes close.

Why is APT so cool? Well, it was the first system to properly handle dependencies in software. Other distros, such as Red Hat, used RPM files that had dependencies. For example, an RPM for the Gimp would have a dependency on Gtk, the graphical toolkit on which the Gimp is based. As a result, if you tried to install your Gimp RPM without having the Gtk RPM, your install would fail. So you grab the Gtk RPM and try again. Aha: Gtk has a dependency on three other things that you need to download. And those three other things have dependencies on 20 other things. And so on, and so on, usually until you can't actually find a working RPM for one of the dependencies, and you give up.

APT, on the other hand, was designed to automatically find and download dependencies for your packages. So if you wanted to install the Gimp, it would download the Gimp's package as well as any other software it needed to work. No more hunting around by hand, no more worrying about finding the right version, and certainly no more need to compile things by hand. APT also handles installation resuming, which means that if you lose your Internet connection part-way through an upgrade (or your battery runs out, or you have to quit, or whatever), APT will just pick up where it left off next time you rerun it.

Day-to-Day Usage

To enable you to search for packages both quickly and thoroughly, APT uses a local cache of the available packages. Try running this command:

sudo apt-get update 


The apt-get update command instructs APT to contact all the servers it is configured to use and download the latest list of file updates. If your lists are outdated, it takes a minute or two for APT to download the updates. Otherwise, this command executes it in a couple of seconds.

After the latest package information has been downloaded, you are returned to the command line. You can now ask APT to automatically download any software that has been updated, using this command:

sudo apt-get upgrade 


If you have a lot of software installed on your machine, there is a greater chance of things being updated. APT scans your software and compares it to the latest package information from the servers and produces a report something like this:

paul@ubuntu:~$ sudo apt-get upgrade Reading package lists... Done Building dependency tree... Done The following packages will be upgraded:   example-content gnome-system-tools libavahi-client3 libavahi-common-data   libavahi-common3 libavahi-glib1 ttf-opensymbol ubuntu-artwork ubuntu-minimal   ubuntu-standard update-notifier 11 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Need to get 27.0MB of archives. After unpacking 147kB of additional disk space will be used. Do you want to continue [Y/n]? 


Each part of that report tells us something important. Starting at the top, the line "the following packages will be upgraded" gives us the exact list of packages for which updates are available. If you're installing new software or removing software, you'll see lists titled "The following packages will be installed" and "The following packages will be removed." A summary at the end shows that there's a total of 11 packages that APT will upgrade, with 0 new packages, 0 to remove, and 0 not upgraded. Because this is an upgrade rather than an installation of new software, all those new packages will only take up 147KB of additional space. Although they come to a 27MB download, they are overwriting existing files.

It's important to understand that a basic apt-get upgrade will never remove software or add new software. As a result, it is safe to use to keep your system fully patched, because it should never break things. However, occasionally you will see the "0 not upgraded" status change, which means some things cannot be upgraded. This happens when some software must be installed or removed to satisfy the dependencies of the updated package, which, as previously mentioned, apt-get upgrade will never do.

In this situation, you need to use apt-get dist-upgrade, so named because it's designed to allow users to upgrade from one version of Debian/Ubuntu to a newer versionan upgrade that inevitably involves changing just about everything on the system, removing obsolete software, and installing the latest features. This is one of the most-loved features of Debian because it allows you to move from version to version without having to download and install new CDs.

Whereas apt-get upgrade and apt-get dist-upgrade are there for upgrading packages, apt-get install is responsible for adding new software. For example, if you want to install the MySQL database server, you would run this:

sudo apt-get install mysql-server 


Internally, APT would query "mysql-server" against its list of software, and find that it matches the mysql-server-5.0 package. It would then find which dependencies it needs that you don't already have installed and then give you a report like this one:

paul@ubuntu:~$ sudo apt-get install mysql-server Reading package lists... Done Building dependency tree... Done The following extra packages will be installed:   libdbd-mysql-perl libdbi-perl libnet-daemon-perl libplrpc-perl   mysql-client-5.0 mysql-server-5.0 Suggested packages:   dbishell libcompress-zlib-perl Recommended packages:   mailx The following NEW packages will be installed   libdbd-mysql-perl libdbi-perl libnet-daemon-perl libplrpc-perl   mysql-client-5.0 mysql-server mysql-server-5.0 0 upgraded, 7 newly installed, 0 to remove and 11 not upgraded. Need to get 28.5MB of archives. After unpacking 65.8MB of additional disk space will be used. Do you want to continue [Y/n]? 


This time you can see that APT has picked up and selected all the dependencies required to install MySQL Server 5.0, but it has also listed one recommended package and two suggested packages that it has not selected for installation. The "recommended" package is just that: The person who made the MySQL package (or its dependencies) thinks it would be a smart idea for you to also have the mailx package. If you want to add it, press N to terminate apt-get and rerun it like this:

apt-get install mysql-server mailx 


The "suggested" packages are merely a lower form of recommendation. They don't add any crucial features to the software you selected for install, but it's possible that you might need them for certain, smaller things.

Note

APT maintains a package cache where it stores .deb files it has downloaded and installed. This usually lives in /var/cache/apt/archives, and can sometimes take up many hundreds of megabytes on your computer. You can have APT clean out the package cache by running apt-get clean, which deletes all the cached .deb files. Alternatively, you can run apt-get autoclean, which deletes cached .deb files that are beyond a certain age, thereby keeping newer packages.


If you try running apt-get install with packages you already have installed, APT will consider your command to be apt-get update and see whether new versions are available for download.

The last day-to-day package operation is, of course, removing things you no longer want. This is done through the apt-get remove command, as follows:

apt-get remove firefox 


Removing packages can be dangerous, because APT also removes any software that relies on the packages you selected. For example, if you were to run apt-get remove libgtk2.0-0 (the main graphical toolkit for Ubuntu), you would probably find that APT insists on removing more than a hundred other things. The moral of the story is this: When you remove software, read the APT report carefully before pressing Y to continue with the uninstall.

A straight apt-get remove leaves behind the configuration files of your program so that if you ever reinstall it you do not also need to reconfigure it. If you want the configuration files removed as well as the program files, run this command instead:

apt-get remove --purge firefox 


That performs a full uninstall.

Note

You can see a more extensive list of apt-get parameters by running apt-get without any parameters. The cryptic line at the bottom, "This APT has Super Cow Powers," is made even more cryptic if you run the command apt-get moo.


Finding Software

With so many packages available, it can be hard to find the exact thing you need using command-line APT. The general search tool is called apt-cache and is used like this:

apt-cache search kde 


Depending on which repositories you have enabled, that will return about a thousand packages. Many of those results will not even have KDE in the package name, but will be matched because the description contains the word KDE.

You can filter through this information in several ways. First, you can instruct apt-cache to search only in the package names, not in their descriptions. This is done with the n parameter, like this:

apt-cache n search kde 


Now the search has gone down from 1,006 packages to 377 packages.

Another way to limit search results is to use some basic regular expressions, such as ^, meaning "start," and $, meaning "end." For example, you might want to search for programs that are part of the main KDE suite and not libraries (usually named something like libkde), additional bits (such as xmms-kde), and things that are actually nothing to do with KDE yet still match our search (like tkdesk). This can be done by searching for packages that have a name starting with kde, as follows:

apt-cache n search ^kde. 


Perhaps the easiest way to find packages is to combine apt-cache with grep, to search within search results. For example, if you want to find all games-related packages for KDE, you could run this search:

apt-cache search games  | grep kde 


When you've found the package you want to install, just run them through apt-get install as per usual. If you first want a little more information about that package, you can use apt-cache showpkg, like this:

apt-cache showpkg mysql-server-5.0 


This shows information on "reverse depends" (which packages require, recommend, or suggest mysql-server-5.0), "dependencies" (which packages are required, recommended, or suggested to install mysql-server-5.0) and "provides" (which functions this package gives you). The "provides" list is quite powerful because it allows several different packages to provide a given resource. For example, a MySQL database-based program requires MySQL to be installed, but isn't fussy whether you install MySQL 4.1 or MySQL 5.0. In this situation, the Debian packages for MySQL 4.1 and MySQL 5.0 will both have "mysql-server-4.1" in the provides list, meaning that they offer the functionality provided by MySQL 4.1. As a result, you can install either version to satisfy the MySQL-based application.



Ubuntu Unleashed
Ubuntu Unleashed 2011 Edition: Covering 10.10 and 11.04 (6th Edition)
ISBN: 0672333449
EAN: 2147483647
Year: 2006
Pages: 318

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net