Beyond Synaptic - using apt for better package management

Beyond Synaptic - using apt for better package management


I'm a Debian user and--like many--I use apt and its associated tools. If you haven't yet discovered apt here's a brief summary of some of it and some of its tools which can make your package management even more powerful.

History

I'll start with a brief history lesson. The 'Advanced packaging tool' was introduced in 1998 and first included in a Debian release (2.1 or slink) in 1999. There is no single apt application to speak of, instead it's a series of tools and functions originally designed as a front-end to dpkg -- the software at the heart of Debian's package management (it now also support RPM backends). There are several front-ends to apt itself including: Synaptic, aptitude and Adept but I want to look specifically at the base command-line tools--not that there's anything wrong with the front-ends.

One of the advantages of apt is the repository management. Like most packaging systems, apt uses its repositories to find and retrieve packages. The way in which repositories are organised aids greatly with dependencies--where one package depends upon another in order to work properly. Apt repositories also make recommendations and suggestions of other packages which might prove useful. These are not dependencies as the original package will run without them but sometimes what you might think of as a dependency will be a recommendation because there is a choice involved. Debian policy is not to dictate.

Because of the nature of these tools the user running them needs certain privileges. Usually this would be done with sudo or--if you are confident--as root.

Anyway, on with the tools.

apt-get update

:~$ sudo apt-get update

Apt makes use of a local cache of packages, detailing the available packages, their version, the files they contain, their dependencies and installation status. Because it's a local cache it needs to be updated with the central lists within remote repositories. This is the equivalent of Synaptic's reload command.

apt-cache

:~$ sudo apt-cache search gnumeric
:~$ sudo apt-cache search spreadsheet
:~$ sudo apt-cache search show inkscape
:~$ sudo apt-cache depends python

Apt-cache is an interface with the local cache. With it you can search for a package by name or description. For example results for the first two commands above will both include the Gnumeric package but obviously the first one will be more accurate. There are a number of options for apt-cache, search is probably the most popular, show will give detailed information on a package, depends will--as it suggests--show the dependencies for a package.

apt-get

:~$ sudo apt-get install gnumeric
:~$ sudo apt-get remove inkscape
:~$ sudo apt-get autoremove

Apt-get is the package management side of apt. Using a single command like the first one will retrieve the gnumeric package and all it's dependencies--and all their dependencies--and install them, keeping you informed as it goes. Before this apt-get will ask you to confirm your choice, giving you such information and the download size and eventual storage space required after unpacking. The remove option will not remove dependencies but will prompt you regarding packages that depend upon the one(s) you are trying to remove. The autoremove option will clean up packages automatically installed as a dependency but not removed when the dependent package is removed.

Like apt-cache, there's much more to apt-get than I can cover here. Check out the man files for more on these powerful commands.

Other useful tools

These tools do not come as part of a default Debian installation so you'll probably need to install them individually.

apt-show-versions

:~$ sudo apt-show-versions gnumeric
:~$ sudo apt-show-versions -u

Apt-show-versions is useful for comparing the versions of a package. Generally this will be the installed one and the one in the repository. Using -u switch will give a list of all installed packages for which a newer version is available.

apt-listbugs

Once installed apt-listbugs is automatically called during an apt-get install process. Before downloading and installing the packages requested (and their dependencies) this will retrieve a list of the critical bugs for them. This is very useful if you are not running a stable version of Debian as you can see which bugs are open, pending or done and look them up before installing.

apt-mirror

If you are running several Debian installations, you can use this to create a local mirror of some or all of a repository to save your internet bandwidth. This can be useful if you want to ensure all your machines are using particular versions of packages.

apt-proxy

This can also be used to keep bandwidth down for multiple machines but instead it works on a proxy basis, caching repositories updates as clients call on them.

apt-listchanges

This will list the most recent changes (from the changelog) to a package before you install it.

apt-zip

If your machine is not-networked, keeping it up to date with apt can be awkward. apt-zip makes this easier by allowing you to store the packages the machine needs on removable media from another--networked--machine.

Conclusion

Whilst Synaptic and Aptitude have their advantages--for example Aptitude will tidy up orphaned dependencies when removing a package--I think there's a lot to be said for the good old apt tools, particularly if you are on a minimal system or in circumstances where you need to conserve bandwidth etc. I don't claim to be anything like an expert on them and I fully expect others with greater experience to embellish what I've said here. If you've only been using Synaptic give apt a try as well.

Category: 

Comments

Bruce Miller's picture

I can find no reference on my up-to-date Kubuntu installation nor in Google Linux to a command "apt-update". Do you perhaps mean "[apt-get|aptitude] update"?

apt-get requires root privileges. Your examples above running from a regular user account (:~$ apt-get ... ) will not work. [U/Ku/Xu]buntu users can of course use "sudo" (as can Debian users who have taken the trouble to set it up).

Ryan Cartwright's picture

Sorry yes they are all typos. It is indeed apt-get update and where I've put ~:$ it's because I took out all the local prompt info and got a little vigorous.

I do of course recommend using sudo for regular users although if you are going to do a lot of stuff it's just as simple to su to root before hand.

Sorry for any confusion - they've all been corrected in the post now--I hope. Thanks for bringing them to my attention.

Ryan

Terry Hancock's picture

I've been using apt tools for a long time now. I actually did look at Synaptic once or twice, but haven't really explored it, because apt-get and apt-cache pretty much solve my problems for me.

I appreciate the run down of the other tools, though, I'm going to have to see if I can find ways to make things even easier for myself with them. :-)

Ryan Cartwright's picture

I've been using apt tools for a long time now. I actually did look at Synaptic once or twice, but haven't really explored it, because apt-get and apt-cache pretty much solve my problems for me.

I'm the same. When I was introducing some new users to Ubuntu (their choice, I use Debian) I had to find out how Synaptic worked so I could show them: it's okay but I prefer apt-cache and apt-get. Aptitude has some advantages, particularly in automatically cleaning up when you remove a package and not the--soon to be orphaned--packages it depended upon. Apt is better at this now by prompting about autoclean though and will be further improved from what I understand.

I have found apt-show-versions to be very handy for remote boxes. We run several small servers in remote offices. Each of these uses apt-show-versions in a script and mails me the results so I know what needs updating and how urgent it is.

Without a doubt though apt-listbugs has been the best discovery for me, particularly as I run Sid on a couple of my boxes.

cheers Ryan

Maurice Cepeda's picture

I liked your review. Even so, I have a few things to say, not about your review so much as with apt.

I don't mean to rain on apt --because using apt-get with fink on OS X allowed me an easy transition to Debian and then later to Ubuntu-- but I think aptitude is the way to go in as far as a lesser learning curve in learning various apt commands and because aptitude does everything apt does.

I remember discovering for myself years before the the apt orphan fiasco became public that apt was not removing my dependencies. #Debian on freenode was apparently not even aware of the situation because all I got from them were bewildered responses.

Correct me if I'm wrong (and I'm sure someone well-versed in the intrinsic apt details will) but Aptitude's done pretty much everything apt has recently gotten to do recently but years ago. ie., aptitude has handled orphaned dependencies since its start.

Sure, apt now autoremoves dependencies but this is just another command one has to learn in addition to the 16/15 apt commands one needs to know.

"If any of you have noticed, that is 16 different [apt] tools that you need to become familiar with"

Aptitude's syntax is easy. You want to install with aptitude?
aptitude install xxxx

You want to remove?
aptitude remove xxxx

Search?
aptitude search xxxx

Doesn't the above look easier than ... ?
apt-get install xxxx
apt-get autoremove xxxx
apt-cache search xxx

Sure it does. It does so because aptitude's syntax is consistent whereas apt's isn't. Look at it from the point of view of someone starting out that wants to use line-command or someone doing system maintenance late at night when you memory starts going foggy (I've been there), you want easy to remember simple and consistent syntax.

As for why there's been so much effort put into apt when aptitude already solved the issue of easy package maintenance, this baffles me considering that this same effort could have gone in to improving something else, markedly. Hmm, like something exciting like adapting the FreeBSD kernel with the Debian userland, Debian GNU/kFreeBSD.

Maurice Cepeda

Terry Hancock's picture

You write as if aptitude were in competition with apt, but AFAIK, aptitude is actually a front end to apt, so everything aptitude does is because of all the work that went into apt.

There are circumstances under which you cannot use a curses-based program, but you can still use line-based programs like apt-get and family. So it's good to know how. And after you know how, it often becomes more trouble than it's worth to remember the other way to do it.

It's not for everybody, obviously, but there are reasons to learn the apt tools.

Ryan Cartwright's picture

AFAIK, aptitude is actually a front end to apt, so everything aptitude does is because of all the work that went into apt.

Whilst the last statement is true, aptitude has long had features which -- although they utilise it -- were not available in apt. Package tidying is one of them. apt has only recently begun to automatically deal with orphaned packages whereas aptitude has done so for a while (presumably by keeping it's own records).

There are circumstances under which you cannot use a curses-based program, but you can still use line-based programs like apt-get and family. So it’s good to know how. And after you know how, it often becomes more trouble than it’s worth to remember the other way to do it.

I agree here. Every time I go into aptitude I get put off by the curses interface. I forget how to do things I want and apt-cache, apt-get etc. just seem to spring to my mind quicker. Plus I've always been more attracted by common denominators for things like this. I've mentioned this on another post but one of the reasons I use free software (and Debian in particular) is because I like the coal-face feeling you get. I really, really dislike systems that make assumptions for you -- without notification -- and for that reason I prefer things like apt-listbugs and apt-showversions.

Maurice Cepeda's picture

"You write as if aptitude were in competition with apt, but AFAIK, aptitude is actually a front end to apt, so everything aptitude does is because of all the work that went into apt."

True, I do write about them in that way.

As for aptitude being an apt front-end, I don't think it's quite so simple because it's documented that aptitude has avoided orphaned dependencies entirely before apt autoremove.

Read about it at,
[http://www.pthree.org/2007/08/12/aptitude-vs-apt-get/]
[http://psychocats.net/ubuntu/aptitude]
I tried posting the above links earlier but they failed to show up in my last post.

If you don't like curses based apps, no problem; You don't have to use the aptitude curses based UI to use aptitude. You can use it form line command. That's what my earlier post alludes. "Actions may be performed from a visual interface or from the command-line." [http://algebraicthunk.net/~dburrows/projects/aptitude/doc/en/rn01re01.html]

As for places where a curses based app isn't optimal, I'm not sure what might fit this bill but there's line command aptitude just as with apt-get but with consistent syntax.

Read about it at (and see the commands listed on my earlier posted comment),
[http://algebraicthunk.net/~dburrows/projects/aptitude/doc/en/ch01s02.html]

Maurice Cepeda's picture

"As for places where a curses based app isn't optimal, I'm not sure what might fit this bill but there's line command aptitude just as with apt-get."
so they are on par, unless you refer to GUI apt front-ends such as Synaptic. I don't think there is anything like that for aptitude, sounds like a good idea for a project.

Bearbonez's picture
Submitted by Bearbonez on

Just a note to mention the Sidux/Aptosid method of using apt to update the whole system (which makes a lot of sense to update without a gui running)
Logout
press Ctrl-Alt-F1 to open the CLI
login as root
apt-get update
apt-get dist-upgrade (-d to download packages only)
apt-get clean
Ctrl-Alt-F7 to return to login prompt
should work on any Debian based system

Don't rush a miracle worker....you get lousy miracles

Author information

Ryan Cartwright's picture

Biography

Ryan Cartwright heads up Equitas IT Solutions who offer fair, quality and free software based solutions to the voluntary and community (non-profit) and SME sectors in the UK. He is a long-term free software user, developer and advocate. You can find him on Twitter and Identi.ca.