How To Check Linux Package Version Before Installing It
======
![Check Linux Package Version][1]
Most of you will know how to [**find the version of an installed package**][2] in Linux. But, what would you do to find the packages’ version which are not installed in the first place? No problem! This guide describes how to check Linux package version before installing it in Debian and its derivatives like Ubuntu. This small tip might be helpful for those wondering what version they would get before installing a package.
### Check Linux Package Version Before Installing It
There are many ways to find a package’s version even if it is not installed already in DEB-based systems. Here I have given a few methods.
##### Method 1 – Using Apt
The quick and dirty way to check a package version, simply run:
```
$ apt show <package-name>
```
**Example:**
```
$ apt show vim
```
**Sample output:**
```
Package: vim
Version: 2:8.0.1453-1ubuntu1.1
Priority: optional
Section: editors
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: Debian Vim Maintainers <[email protected]>
N: There is 1 additional version. Please use the '-a' switch to see it
```
**Apt** is the default package manager in recent Ubuntu versions. So, this command is just enough to find the detailed information of a package. It doesn’t matter whether given package is installed or not. This command will simply list the given package’s version along with all other details.
##### Method 2 – Using Apt-get
To find a package version without installing it, we can use **apt-get** command with **-s** option.
```
$ apt-get -s install vim
```
**Sample output:**
```
NOTE: This is only a simulation!
apt-get needs root privileges for real execution.
Keep also in mind that locking is deactivated,
so don't depend on the relevance to the real current situation!
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
ctags vim-doc vim-scripts
The following NEW packages will be installed:
vim
0 upgraded, 1 newly installed, 0 to remove and 45 not upgraded.
Inst vim (2:8.0.1453-1ubuntu1.1 Ubuntu:18.04/bionic-updates, Ubuntu:18.04/bionic-security [amd64])
Conf vim (2:8.0.1453-1ubuntu1.1 Ubuntu:18.04/bionic-updates, Ubuntu:18.04/bionic-security [amd64])
```
Here, -s option indicates **simulation**. As you can see in the output, It performs no action. Instead, It simply performs a simulation to let you know what is going to happen when you install the Vim package.
You can substitute “install” option with “upgrade” option to see what will happen when you upgrade a package.
```
$ apt-get -s upgrade vim
```
##### Method 3 – Using Aptitude
**Aptitude** is an ncurses and commandline-based front-end to APT package manger in Debian and its derivatives.
To find the package version with Aptitude, simply run:
```
$ aptitude versions vim
p 2:8.0.1453-1ubuntu1 bionic 500
p 2:8.0.1453-1ubuntu1.1 bionic-security,bionic-updates 500
```
You can also use simulation option ( **-s** ) to see what would happen if you install or upgrade package.
```
$ aptitude -V -s install vim
The following NEW packages will be installed:
vim [2:8.0.1453-1ubuntu1.1]
0 packages upgraded, 1 newly installed, 0 to remove and 45 not upgraded.
Need to get 1,152 kB of archives. After unpacking 2,852 kB will be used.
Would download/install/remove packages.
```
Here, **-V** flag is used to display detailed information of the package version.
Similarly, just substitute “install” with “upgrade” option to see what would happen if you upgrade a package.
```
$ aptitude -V -s upgrade vim
```
Another way to find the non-installed package’s version using Aptitude command is:
```
$ aptitude search vim -F "%c %p %d %V"
```
Here,
* **-F** is used to specify which format should be used to display the output,
* **%c** – status of the given package (installed or not installed),
* **%p** – name of the package,
* **%d** – description of the package,
* **%V** – version of the package.
This is helpful when you don’t know the full package name. This command will list all packages that contains the given string (i.e vim).
Here is the sample output of the above command:
```
[...]
p vim Vi IMproved - enhanced vi editor 2:8.0.1453-1ub
p vim-tlib Some vim utility functions 1.23-1
p vim-ultisnips snippet solution for Vim 3.1-3
p vim-vimerl Erlang plugin for Vim 1.4.1+git20120
p vim-vimerl-syntax Erlang syntax for Vim 1.4.1+git20120
p vim-vimoutliner script for building an outline editor on top of Vim 0.3.4+pristine
p vim-voom Vim two-pane outliner 5.2-1
p vim-youcompleteme fast, as-you-type, fuzzy-search code completion engine for Vim 0+20161219+git
```
##### Method 4 – Using Apt-cache
**Apt-cache** command is used to query APT cache in Debian-based systems. It is useful for performing many operations on APT’s package cache. One fine example is we can [**list installed applications from a certain repository/ppa**][3].
Not just installed applications, we can also find the version of a package even if it is not installed. For instance, the following command will find the version of Vim package:
As you can see in the above output, Vim is not installed. If you wanted to install it, you would get version **8.0.1453**. It also displays from which repository the vim package is coming from.
##### Method 5 – Using Apt-show-versions
**Apt-show-versions** command is used to list installed and available package versions in Debian and Debian-based systems. It also displays the list of all upgradeable packages. It is quite handy if you have a mixed stable/testing environment. For instance, if you have enabled both stable and testing repositories, you can easily find the list of applications from testing and also you can upgrade all packages in testing.
Apt-show-versions is not installed by default. You need to install it using command:
```
$ sudo apt-get install apt-show-versions
```
Once installed, run the following command to find the version of a package,for example Vim: