How to Install Specific Version of Package using apt-get

To handle Debian-based system packages, we use the apt-get command. This command requires administrative rights to work. It contains several options that make it possible to manipulate the packages through some operations like the installation, update or deletion, and many others. The beautiful thing is the fact that it allows installing a specific version of a package and the purpose of this tutorial we are using Ubuntu 16.04 version.

Read Also How to List Installed Packages by Date on Linux

1) Check the available versions of packages

Sometimes you can face issues or bug with a version of a package, this may cause you to choose a version which doesn't encounter bugs. Before installing, it is possible to check the available versions of a package with the apt-cache madison command. The syntax is

apt-cache madison package

You can see the output below

$ apt-cache madison virtualbox
virtualbox | 5.0.40-dfsg-0ubuntu1.16.04.2 | xenial-updates/multiverse amd64 Packages
virtualbox | 5.0.18-dfsg-2build1 | xenial/multiverse amd64 Packages

You can also use the syntax command below

apt-cache policy package

just as below

$ apt-cache policy virtualbox
 Installed: (none)
 Candidate: 5.0.40-dfsg-0ubuntu1.16.04.2
 Version table:
 5.0.40-dfsg-0ubuntu1.16.04.2 500
 500 xenial-updates/multiverse amd64 Packages
 5.0.18-dfsg-2build1 500
 500 xenial/multiverse amd64 Packages

Then, with one of the two commands, you can decide to check the available version of a package with the releases versions on the official site or on the official GitHub.

2) Install a specific version of a package

When you have listed the versions to choose the specific one, you can install it with the apt-get install command followed by the name and the version of the package. So, you need to follow the syntax as below:

apt-get install package=version -V

The -V parameter helps to have more details about the installation

Practically, you can do as below:

# apt-get install virtualbox=5.0.18-dfsg-2build1 -V
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
   dkms (
   libgsoap8 (2.8.28-1)
   libqt4-opengl (4:4.8.7+dfsg-5ubuntu2)
   libsdl1.2debian (1.2.15+dfsg1-3)
   libvncserver1 (0.9.10+dfsg-3ubuntu0.16.04.1)
   virtualbox-dkms (5.0.40-dfsg-0ubuntu1.16.04.2)

a. Simulate the installation

For some reason, you could need to make sure that the installation will not encounter any problem. To do that, it is possible to simulate the installation with the -s parameter respecting the syntax

# apt-get install -s package

as below

# apt-get install -s virtualbox=5.0.18-dfsg-2build1

You can see that it shows the process of the installation but it is a just a simulation.

b. List the installed packages with the versions

You can need to check the version of an installed package. You can do it with the dpkg command combined with grep followed by the name of the package

# dpkg -l | grep virtualbox
ii  unity-scope-virtualbox    0.1+13.10.20130723-0ubuntu1     all      VirtualBox scope for Unity
ii  virtualbox                5.0.18-dfsg-2build1             amd64    x86 virtualization solution - base binaries
ii  virtualbox-dkms           5.0.40-dfsg-0ubuntu1.16.04.2    all      x86 virtualization solution - kernel module sources for dkms

If you want to filter the information, you can use the command as below

# dpkg -l | grep '^ii' | grep virtualbox | awk '{print $2 "\t" $3}'
unity-scope-virtualbox	0.1+13.10.20130723-0ubuntu1
virtualbox	 5.0.18-dfsg-2build1
virtualbox-dkms	 5.0.40-dfsg-0ubuntu1.16.04.2

To list all the installed packages with version, you can omit the grep followed by the name of a specific package.

Install a specific version of a package can be useful to avoid the bugs when you know which version of a package is concerned and make sure to disable specific package upgrade (in /etc/yum.conf file )so it won't get automatically upgraded when run yum update.

Alain Francois 12:05 am

About Alain Francois

IT Linux administrator passionate of free and open source software, I work on Linux Systems since some years on installations and deployments of certain solutions. I like to share my experiences with a wider audience by training and conferences.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.