Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to setup a new virtual machine with some specified packages (name and version), that are provided.

For example apache2 in version 2.2.20-1ubuntu1 with all dependencies. Even if there is a new version of this package on the servers this one should be installed.

The solution has to work/scale with multiple (n) "setups". Another virtual machine might need an older version of apache2.

I currently know of some possibilities that install the exact packages, but do not scale that good:

  1. Copy all required *.deb to every virtual machine manually and enter: dpkg -i ... -> Could work, but it is very error prone. (Manual scripts etc.)
  2. Create and use a new Ubuntu repository for each setup. -> Does not work because I would need n repositories.
  3. Setup the machine once and copy the VM / create a snapshot. -> Does not work because I would need to store n VMs.

My problem could be labeled as patch management, but I do not want to update my packages to the current version. My goal is to install old packages.

share|improve this question
up vote 102 down vote accepted

You can use apt-get to install a specific version of the package a long as it is in an archive that apt knows about. From the apt-get manpage:

A specific version of a package can be selected for installation by following the package name with an equals and the version of the package to select. This will cause that version to be located and selected for install. Alternatively a specific distribution can be selected by following the package name with a slash and the version of the distribution or the Archive name (stable, frozen, unstable).

For example, you could do:

sudo apt-get install apache2=2.2.20-1ubuntu1

Note that you may need to do some dependency resolution on your own in this case, but if there are any problems apt-get will tell you what is causing them. On my 11.10 system I would need to do the following to get this to work:

sudo apt-get install apache2=2.2.20-1ubuntu1 \
                     apache2.2-common=2.2.20-1ubuntu1 \
                     apache2.2-bin=2.2.20-1ubuntu1 \
share|improve this answer
This helped fix a problem of mine. Thanks! – pthurmond Sep 20 '13 at 20:00
how to know which versions are available? – Rodrigo Gurgel Jan 25 '15 at 15:51
@Rodrigo Gurgel, "aptitude versions apache2" – user169015 Jan 11 at 9:52
@user169015 "version exists" != "version is packaged for Ubuntu and available with apt" – Kyle Strand Jan 11 at 16:55
Hi Kyle, I didnt get your comment, though Yes, package can be installed using apt as well. I just stick on with aptitude because I have been using that for a long time... :) – user169015 Jan 12 at 7:21

To check which versions are available, you can check via:

sudo apt-cache madison ^apache2

Then copy the version or use the following syntax:

sudo apt-get install apache2=2.2\*

To check which version you've installed, run:

dpkg -l 'apache2*' | grep ^i
share|improve this answer
Thanks a lot for pointing out the =2.2\* option as a way to use a wildcard for selecting any available subversion. Thats what I wanted to know but didn't know how to ask :) – The Sexiest Man in Jamaica Apr 16 '15 at 14:31
When listing the versions using dpkg -l <packageName>, the version number is sometimes truncated. To avoid this, use COLUMNS=100 dpkg -l <packageName> – CJBS Jun 10 '15 at 17:57

Practically speaking, this isn't possible because the old versions are not kept in the archive, so unless you have a copy of the old version laying around somewhere, you can't install it. You should be asking yourself why you want to install an older version in the first place. On a stable release, the main reason for a new version being released is to correct a security vulnerability, and you don't want to be running a vulnerable server do you?

share|improve this answer
I need this to reproduce exact copies of old environments for development purposes. Is it possible to setup a mirror that does not delete old package versions to access the required packages or do I need to setup multiple repositories that only hold diffs? – ayckoster Jan 2 '12 at 14:57
@psusi: Not exactly a fair response, there might be many reasons. In my case the newer version might actually have a bug, and to double check that is the case the older version is needed. Just an example. – Cookie Mar 28 '14 at 21:23
@nomen, no, it is a single distro that does not use a rolling release model. Great care is taken to ensure that when critical bugs and security vulnerabilities are fixed in the stable release, that they do not cause regressions, but if it does happen, then file a bug report tagged with regression-release and it will be fixed or rolled back. – psusi Apr 5 '14 at 23:48
@nomen, if you want to make up your own meanings for words you will have a hard time communicating with others. For everyone else in the world, that is not what a rolling release is, and rolling release is the exact opposite, and thus, mutually exclusive with stable release. And now that I think about it, the original version shipped with the release is actually kept in the -release pocket, and updates go to the -updates or -security pocket, so while you can't go back to a previous update, you can go back to the originally released version. – psusi Apr 6 '14 at 1:17
@psusi: Here is another one for you. Unison is required to always be the same version on all machines. Yet on 13.10 it is a different version than in 12.04 LTS. So now what? When coming to a question like this, receiving an answer like why do you want to do this is really incredibly unhelpful and a waste of time for everyone. – Cookie Apr 15 '14 at 7:01

I'll expand on earlier answers with other handy versioning commands in the apt family. To see which versions are available, run apt-cache policy:

# apt-cache policy apache2
  Installed: (none)
  Candidate: 2.4.7-1ubuntu4.5
  Version table:
     2.4.10-1ubuntu1.1~ubuntu14.04.1 0
        100 trusty-backports/main amd64 Packages
     2.4.7-1ubuntu4.5 0
        500 trusty-security/main amd64 Packages
     2.4.7-1ubuntu4 0
        500 trusty/main amd64 Packages

Then, as mentioned elsewhere, install a specific version with apt-get:

# apt-get install apache2=2.4.7-1ubuntu4.5

You can now see which version you have installed by running apt-cache policy again:

# apt-cache policy apache2
  Installed: 2.4.7-1ubuntu4.5
  Candidate: 2.4.7-1ubuntu4.5
  Version table:
     2.4.10-1ubuntu1.1~ubuntu14.04.1 0
        100 trusty-backports/main amd64 Packages
 *** 2.4.7-1ubuntu4.5 0
        500 trusty-security/main amd64 Packages
        100 /var/lib/dpkg/status
     2.4.7-1ubuntu4 0
        500 trusty/main amd64 Packages

If you don't want newer versions to be installed on updates, pin the package with apt-mark:

# apt-mark hold apache2
apache2 set on hold.

Let's say a new version of apache2 is added to the package index and your machine is synced with apt-get update. You'll see this when you next run apt-get upgrade:

# apt-get upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.