Your Debian Aptitude

Submitted by Larry on 19 August 2005 - 9:16pm

As various associates and friends of mine know, my typical Linux distribution of choice is Debian. Once upon a time, the main thing that differentiated Debian from other distributions was a nifty suite of tools called APT, or Advanced Packaging Tool. While users of "those other distributions" wallowed in RPM hell, having to track down package dependencies manually, Debian users relied on a vast online archive of packages all parsed by the apt system. By using the apt-get tool Debian users could install one package, and all required dependencies would be installed and configured automagically. No scouring the 'Net for a specific version of an RPM. Coolness!

Of course, most distributions noticed that this was a really cool idea, and have since either cloned or ported it. It's a sorry distribution these days that doesn't have some sort of automagic package dependency tracking (whether binary or source based like Gentoo), and if you throw a CD you're likely to hit a distribution that uses apt of some kind. That's the power of open source development at its best; sharing ideas and letting the good ones win.

(To be accurate, it should be pointed out that Apt is not comparable to RPM. Dpkg is the Debian equivalent to RPM, as it is the package manager and format itself. Apt, Yum, and other dependency managers are a level above the package manager, just as the package manager is a level above the tar.gz file. So please, no Apt vs. RPM flamewars, as that's apples to oranges. Thanks. :-) )

Of course, Debian didn't sit still. Apt is a great system, but the interface(s) to it, well... On the command line, you have a suite of tools, some of which are part of the base Apt system and some of which aren't:

  • apt-get: Installs and removes packages, and updates the local cache of what packages are available.
  • apt-cache: Maintain and search the local cache of what packages are available.
  • apt-listbugs: List what bugs (if any) are registered against a given package before you install it (very useful for people like me who run the Sid/Unstable version).
  • apt-listchanges: Same thing, but for non-bug changes.
  • apt-rdepends: Tool for viewing dependency trees.
  • deborphan: Try and figure out what packages are installed that you don't really need.
  • debfoster: Helps deborphan figure out what packages you don't need anymore, but only if you knew to install it before you installed the package.
  • dpkg: The RPM-equivalent for Debian, you have to use dpkg half the time to do various maintenance tasks.

Why all of the differently named programs? And why is updating the local cache part of apt-get instead of apt-cache? That's to say nothing of the usability problems that the name "apt-get" creates. I can't count the number of times people new to Debian (myself included) tried to run apt-get pkgname instead of apt-get install pkgname. I'm already getting, why do I need to say it twice? And then there's always the method of uninstalling a package: apt-get remove pkgname, or if you want to remove the configuration files as well it's apt-get --purge remove. "Get Remove"? "Get Purge Remove", not "Get Remove Purge"? That's right up there with the immortal question, "Why do I have to Start in order to Shutdown?"

Moreover, apt-get is a one-way tracker. Install package A, which requires package B. Then remove package A. Package B is still sitting there on your system taking up space, and hopefully nothing else. deborphan can help, but it isn't perfect. Then there's apt-cache search, which does simple text searching on every package's description and returns an unordered list of packages, generally containing far more than reasonably match.

And then there's the console-GUI, dselect. The less said about dselect the better. It is an excellent example of how not to build a console-GUI application, and I would recommend it for required study in HCI classes if it weren't likely to result in severe mental trauma. Let us not mention it again.

So with all of these problems with the Apt system, what did the Debian folks do? They demonstrated their aptitude for problem solving.

Aptitude is the "next generation apt" program. You want to use it. Full stop. Why? Well, there are a couple of reasons.

First of all, it greatly simplifies the interface. apt-get and apt-cache functionality has now been integrated into a single application (as well as various of the other utilities) without the "Start Shutdown" type confusion:

  • aptitude update: Update the local cache of available packages (formerly apt-get update.
  • aptitude upgrade: Upgrade available packages (formerly apt-get upgrade).
  • aptitude dist-upgrade: Upgrade available packages even if it means removing stuff (formerly apt-get dist-upgrade).
  • aptitude install pkgname: Install package (formerly apt-get install).
  • aptitude remove pkgname: Uninstall package (formerly apt-get remove).
  • aptitude purge pkgname: Uninstall package and config files (formerly apt-get --purge remove).
  • aptitude search string: Search for a package with "string" in the name or description (formerly apt-cache search string).
  • aptitude show pkgname: Show detailed of a package (formerly apt-cache show pkgname).
  • aptitude clean: Delete downloaded package files (formerly apt-get clean).
  • aptitude autoclean: Delete only out-of-date package files but keep current ones (formerly apt-get autoclean).
  • aptitude hold pkgname: Fix a package at its current version and don't upgrade it automatically (formerly an obscure echo-to-file command). unhold to remove the hold.

And so on. Seems nicer already, doens't it? It gets better. Aptitude's search results are by default sorted alphabetically, and shown in a justified column format instead of haphazardly like apt-cache output. It even flags which of them are already installed, which are installable, which are virtual packages, which are on hold, etc. That makes finding a package much easier. When installing a package, aptitude will by default show you what other packages are recommended or suggested but not, strictly speaking, required. That gives you the chance to install those, too, if you think they make sense.

More importantly, aptitude supports two-way dependency tracking. That is, if you install package A which requires package B, then remove package A, aptitude will check to see if anything else you've installed recently requires B. If not, it will let you know that B is now a waste of disk space and will be removed; no need to play with deborphan or debfoster. It only works if you used aptitude to install the packages in the first place, but if you just stick to aptitude then it's much easier than remembering to install debfoster on every system.

And what about a console-GUI to replace the evil-program-that-shall-not-be-named? Aptitude is its own console-GUI. Simply run aptitude with no parameters and up pops a console-GUI version for your downloading pleasure. It's still not as clean as a true GUI application (few complex console-GUIs are), but it's light-years ahead of you-know-what. It has a better online help system, a more standard menu, and an integrated copy of Minesweeper. Coolness!

The only downside to aptitude is that, unlike apt-get, it does not have Super Cow Powers. While disappointing, it's an acceptable trade off for a much more functional, flexible, and usable dependency management system.

So if you're using Debian, put down the apt-get and give aptitude a try. If you're using some other apt-based or apt-using distribution, see if it has aptitude. If it doesn't, switch to a distribution that does. And while you're at it, give a big round of applause to Daniel Burrows, the man behind aptitude. Thanks, Daniel!

It was dealing with all of the dependency BS that led me to FreeBSD. The 'ports' system (not to be compared with Gentoo's, mind you; there are differences) offers what you're suggesting and has since I started using it in 1999. I also prefer the social framework of FreeBSD--one place to ask questions, one place for the source, etc. This isn't meant as flamebait, but you might investigate the ports system.

Dennis Clark (not verified)

26 January 2006 - 5:21pm

I'm not impressed.

I just used aptitude to install a simple Perl XML parser (after reading your blog comments) and it decided that my cvs install was not used and deleted that and a couple dozen other packages that I WAS USING. when I ask something to do an install, I DON'T expect it to arbitrarily delete unrelated packages. Aptitude just got used for the LAST time on my system!

A VERY unhappy Debian user,
DLC

My guess: since aptitude keeps its own record of installed packages apart from apt-get you need to make it aware of all the packages already installed through apt-get. Run 'aptitude keep-all ; aptitude update ; aptitude upgrade'. You're ready to go.

And yes: I know I'm a few years too late responding.

voxluna (not verified)

12 February 2006 - 8:40am

I've been using Aptitude almost as long as Debian, which is about 3 years now. To DLC: 1) Aptitude, like apt-get, should warn you if packages are going to be removed, and assuming it did, how is that Aptitude's fault? 2) It tries to keep things tidy by removing "unneeded" packages (the "two-way dependency" above). It may deem a package so if it hasn't been installed using Aptitude, which is what may have happened to you. But even still, see #1.

Using and understanding aptitude wil make any Debian User into a happy Debian User.

If used from teh beginning of a system you will have logs showing everything you have ever done installed, etc.

So if you EVER have a Problem, you can backtrack and handle.

All the APT functionallity is included.

For those who like there is even a grafical interface.

And as mentioned above, simply doing an uninstall without having read all aptitude parameters and having understood them is quite foolish and produces unwanted results, just as with ANY programm that is just being used without having understood it's functionallity.

I have to agree with Dennis. I just tried aptitude (I usually use apt-get and dselect, which I've actually gotten quite used to.) It told me that it was going to upgrade some packages and remove others. Naively, I assumed that it was going to be very conservative in removing packages, only removing unusable, orphaned packages. Instead, it started removing all sorts of stuff that I use, and I quickly Ctrl-C'ed it. Yes, I should have been more cautious in reading over the remove list, but this is unacceptable.

Apt-get is like the lazy housekeeper you fired for not throwing out the moldy leftovers in the refrigerator. Yes, she always did exactly what you told her to do, but you need someone with a brain too.

Aptitude is like a new housekeeper. She wants to keep the place clean, but needs some direction from you. When she cleans out the refrigerator on her first day of work, she doesn't always know what you want to keep and what you want to throw away. She knows you're busy, so she'll try to figure it out on her own, but she'll ask you before she throws anything away.

When moving from apt-get to aptitude, there are transitional issues. If in the past you have been using apt-get, deselect, and dpkg-* to install and configure the system, aptitude doesn't know what you want. Aptitude offers to uninstall the packages that you've never told her you want to keep. It thinks the packages are just cruft because they aren't in its database. But once you tell her, she doesn't forget.

If, on the other hand, the system has been administered via aptitude from the get-go, aptitude's database will be up-to-date.

In order to make the transition to aptitude in a more orderly way, open aptitude in full-screen mode the first time (she tries to look nice for you, too!):

   # aptitude

Then type the letter "g". Aptitude will show you what its default configuration is telling it to do. The actions will be broken into several categories. Packages that it has never seen before will be on a list that says "--Packages to be removed". (If the list isn't expanded, select the list and hit Enter on your keyboard.) Take a look at the list. If you want them all to stay, select the heading and hit the + on your keyboard, which will tell it to keep all of them and upgrade them if need be.

Then type the letter "q", which will take you back to the original screen. Typing "g" again will take you to the list again, but this time taking into account your instruction to keep or upgrade the packages. Make any adjustments you want. You might want to cycle through g and q a few times to make sure everything is the way you expect. When you are satisfied, type "g" again. Aptitude will dutifully clean up your system and keep it clean for as long as you use it.

If you occasionally use apt-get, aptitude won't get upset. She'll just ask if you want to keep the stuff her rival left behind. Some packages have scripts that still use "apt-get" (e.g., EasyUbuntu), so every once in a while you may have to tell aptitude to keep the packages apt-get installed.

That said, aptitude happily will do things the way YOU want. If you don't like the default behavior, you can always change it by selecting "Dependency Handling" in the "Options" menu. The option that changes the behavior Dennis and Joshua cite is "Remove unused packages automatically."

Since I made the switch to aptitude, my system stays much cleaner, and I break things much less often. ;-)

IMHO, Larry is exactly on-target in his observations in this blog. Aptitude is smart, hardworking, and obedient. The more you use her, the happier you will be.

Happy Trails,

Loye Young
http://www.IYCC.net
Laredo, Texas

P.S., My girlfriend just read what I wrote about aptitude. Her response: "Yeah, but how does her backend look?" I assured her that aptitude's backend has no bloat, either.

Anonymous (not verified)

11 April 2007 - 11:32am

This is a nice hommage to aptitude. However, there is one important point that is not mentioned: apt-file. This allows to find an executable, a library or whatever in packages that are not installed! This makes debian much more convenient than other distros. A standard every-day task, I think. Unfortunately, this functionality has not yet been introduced into aptitude.

Michael.

loyeyoung (not verified)

31 May 2007 - 8:54pm

In reply to by Anonymous (not verified)

To find a package by name or description using aptitude:

# aptitude search your-package-name

Apt-file does have other functionality, which is often helpful, that neither apt-get nor aptitude provide. Apt-file will happily co-exist with aptitude, so if it's of help to you, install it.

I think it would not be difficult to add the apt-file functions to aptitude. Perhaps such a suggestion could be made to aptitude's author, or (better yet) a patch could be submitted that further strengthens aptitude's functionality.

Loye Young
http://www.iycc.biz
Laredo, Texas

Anonymous (not verified)

25 January 2010 - 8:23am

In reply to by Anonymous (not verified)

I guess that depends on one's preferences. I personally think aptitude puts pacman to shame. There are some things I like about pacman, but overall it just felt wrong. Installing a package should be called installing a package, not synchronizing it. With aptitude if I search for a package it lists all packages that match my search including a status flag telling me weather or not the package is installed. With pacman, I have to choose weather to search installed packages or repository packages. Searching the repository is called a synchronize search, which makes about as much sense as synchronizing a package to install it. If I search the repository pacman lists all packages that matched my search but no indication of weather any of them are installed or not.

Anonymous (not verified)

10 May 2010 - 4:03pm

Realizing that this article is almost 5 years old, and the latest comment was from over 5 months ago, but that people will probably continue coming here, I have this little tidbit to share. So I started up aptitude, pressed u for update, and aptitude went through it's updating. It found some duplicates in sources.list, and then, APTITUDE recommended that I run apt-get update!! Aptitude itself is giving me advice that contradicts your advice! I thought that was just a little funny...