18 November 2011

HowTo: Use APT or Aptitude to install specific packages (Debian, Ubuntu)

Debian's APT, the Advanced Package Toolkit, is a fantastic command-line frontend for the dpkg package handler.  Together with 'aptitude' and 'the 'apt-get' families of tools, Debian's package installation and dependency handling is a very powerful set of tools to keep your OS and software updated.  There are graphical frontends to APT and dpkg, such as Synaptic, but today we're working with the CLI.

As I mentioned, dependency handling on Debian and its derivatives (such as Ubuntu) is a breeze.  What happens when you need a specific version of a program, however?  What if an update breaks an application because, say, your website requires a specific version of PHP or your SingleClick UltraVNC client will only connect to a specific version of XTightVNCViewer?  The APT family of tools can help you to find specific versions of software, install those versions, and hold (or pin) that software version.

First, of course, let's update our catalog of available software.  I use 'aptitude' for this and as many installation options as I can, since aptitude has better dependency handling than apt-get.  (aptitude is also a bit more finicky, so if it doesn't like my upgrade path, sometimes I'll bypass it with apt-get.  Anyways...)  So first, we update our catalog:

root-shell# aptitude update
Hit http://debian.uchicago.edu squeeze Release.gpg
Ign http://debian.uchicago.edu/debian/ squeeze/contrib Translation-en                                                                                           
Ign http://debian.uchicago.edu/debian/ squeeze/contrib Translation-en_US                                                                                        
Ign http://debian.uchicago.edu/debian/ squeeze/main Translation-en                                                                                              
Ign http://debian.uchicago.edu/debian/ squeeze/main Translation-en_US                                                                                           
Ign http://debian.uchicago.edu/debian/ squeeze/non-free Translation-en                                                                                          
Ign http://debian.uchicago.edu/debian/ squeeze/non-free Translation-en_US                                                                                       
Hit http://debian.uchicago.edu squeeze-updates Release.gpg                                                                                                      
Ign http://debian.uchicago.edu/debian/ squeeze-updates/contrib Translation-en                                                                                   
Ign http://debian.uchicago.edu/debian/ squeeze-updates/contrib Translation-en_US                                                                                
Hit http://security.debian.org squeeze/updates Release.gpg
...
...
...
root-shell#  

We'll use 'apt-cache policy' to see which versions of a package we have; for an example with ffmpeg, we have:

root-shell#  apt-cache policy ffmpeg
ffmpeg:
  Installed: 5:0.7.7-0.0
  Candidate: 5:0.7.7-0.1
  Version table:
     5:0.7.7-0.1 0
        500 http://www.debian-multimedia.org/ squeeze/main i386 Packages
 *** 5:0.7.7-0.0 0
        100 /var/lib/dpkg/status
     4:0.5.5-1 0
        500 http://security.debian.org/ squeeze/updates/main i386 Packages
     4:0.5.4-1 0
        500 http://debian.uchicago.edu/debian/ squeeze/main i386 Packages

This output gives some very specific information.  There are four versions available, three of which aren't installed with their 'apt preference' set to 500 (more on that in the upcoming HowTo: Pinning Debian and Ubuntu Packages), and the installed version (marked with ***) with its apt preference set to 100.

We also get to see the repository for each package, in case we want to use a specific maintainer's package (such as the Debian Multimedia repository).

If we needed to install a specific version from the above list, we can specify that with:

root-shell#  aptitude install ffmpeg=4:0.5.5-1

This works with 'apt-get install ffmpeg=4:0.5.5-1' as well, which will have different dependency handling; I try to only fall back to apt-get if aptitude is really looking for trouble and wants to remove things that I think it shouldn't.  I'm not necessarily right, of course!


I'll write up an article on Aptitude Pinning soon, so stay tuned, readers.  (I have some less focused info here about it).

0 comments: