511

My questions are divided into two parts:

  1. How to know the version of installed package?
  2. How to install a specific package version?
Braiam
  • 67,791
  • 32
  • 179
  • 269
  • 24
    Please do not vote to delete this post. It is useful as a signpost. Duplicates serve to guide others to the right Q&A. – terdon Aug 17 '16 at 13:39

2 Answers2

613

How to know the version of installed package?

apt-cache policy <package name>

The above command will shows installed package version and also all the available versions in the repository according to the version of Ubuntu in which you are running.It doesn't display the package version which was intended for another version of Ubuntu(not your's).

Example:

$ apt-cache policy gparted
gparted:
  Installed: 0.16.1-1
  Candidate: 0.16.1-1
  Version table:
 *** 0.16.1-1 0
        500 http://ubuntu.inode.at/ubuntu/ saucy/main amd64 Packages
        100 /var/lib/dpkg/status

So the installed gparted version is 0.16.1-1.

How to install a specific package version?

sudo apt-get install <package name>=<version>

Example:

$ sudo apt-get install gparted=0.16.1-1
Reading package lists... Done
Building dependency tree       
Reading state information... Done
gparted is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 265 not upgraded.
andrybak
  • 337
Avinash Raj
  • 78,556
  • 1
    Can you please give more details for the second command? Are there any limitations? For example, could someone on 12.04 install a version of a package available in 13.10? – DK Bose Mar 03 '14 at 11:03
  • 1
    In aptitude pressing Enter on the package name displays information about the package and on the bottom of this screen there is a list of the available versions. – karatedog Feb 12 '16 at 08:36
  • Does the similar usage of apt-cyg work in Cygwin: apt-cyg install package=version? – Danijel Oct 18 '16 at 08:36
  • 8
    In every case I've ever tried this I always get the error The following packages have unmet dependencies:, followed by a list of packages. Any way to make it resolve that automatically? – Hubro Dec 05 '16 at 04:32
  • 6
    Please note that it will most likely fail, because there is usually only 1 or 2 versions of the package that are available in the repository. If you want a different version than currently designed for your distribution, you might need to download it and install with sudo dkpg -i <package-file>. Dependency errors need to be resolved by downloading and installing (also with dkpg) all missing packages (this can take many iterations). Alternatively you can download the program source code, compile it and install it (this also requires manual dependency resolution). – nuoritoveri Jan 03 '17 at 09:16
  • 3
    To list all options: apt list madison – FabricioFCarv Jan 25 '19 at 13:48
  • 3
    @FabricioFCarv what is madison? I found apt list -a <packagename> works (apt list even hints the -a switch when more than one package version is available) – dualed Sep 16 '19 at 10:19
  • 4
    @dualed apt understands madison as a , so it does nothing if that package does not exist (You can test it with apt list asdasdas <packagename>). Your command is the correct one -> apt list -a <packagename> – Madacol Feb 17 '20 at 21:15
  • just an example with an old package, so the "apt list" accept more than one args: One could use, instead of old madison: apt list tmux gcc mtr-tiny... like that. With "-a" parameter, you get all versions – FabricioFCarv Jul 01 '20 at 20:52
  • I didn't find it clearly documented, but wildcards may be a useful way of maintaining a stable major.minor while allowing patch upgrades. – Brent Bradburn Dec 20 '22 at 01:45
  • This doesn't seem to work. ```sudo apt install openssh-client=9.2p1-2 Reading package lists... Done Building dependency tree... Done Reading state information... Done Package openssh-client is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source However the following packages replace it: openssh-server

    E: Version '9.2p1-2' for 'openssh-client' was not found``` but that is the version I currently have installed! it should be found.

    – majorgear Aug 21 '23 at 16:36
31

There is no general way to check the version of installed packages, but most of them can be checked using the command:

command -v 

for example to know the version of apache2:

apache2 -v

But this may not work with other packages so the best practice is to search the manual.

man XXX

and search for the option of showing the version.

To install a specific version of a package:

sudo apt-get install package=version

For example:

sudo apt-get install apache2=2.3.35-4ubuntu1
Aditya
  • 13,416
Maythux
  • 84,289