Ubuntu: How do I get the version of an application from the command line?



Question:

I would like to know how to get the version information of an installed program that doesn't have the

--version or -version

method implemented.


Solution:1

You can use dpkg or apt-cache.

To check the version of bash, for example:

dpkg -l bash    apt-cache show bash  


Solution:2

If the program doesn't have any command line option that displays version information you can try to use dpkg to get the package version which usually contains the program version ion some way.

dpkg -S "$(which YOUR_PROGRAM)"  

prints the package that contains YOUR_PROGRAM, and

dpkg --status YOUR_PACKAGE | grep ^Version  

prints the version of YOUR_PACKAGE.

You can put it all together:

dpkg --status "$(dpkg -S "$(which YOUR_PROGRAM)" | cut -d: -f1)" | grep ^Version  

Use it for example like this for ls:

dpkg --status "$(dpkg -S "$(which ls)"| cut -d: -f1)"| grep ^Version  


Solution:3

The below command also gives you the exact installed package version.

apt-cache policy <package-name> | grep Installed: | cut -d: -f2  

Example

$ apt-cache policy firefox | grep Installed: | cut -d: -f2  24.0+build1-0ubuntu1    $ apt-cache policy gedit | grep Installed: | cut -d: -f2  3.8.3-0ubuntu3  


Solution:4

You can use dpkg-query to get the version of a package:

$ dpkg-query -W -f='${binary:Package} ${Version}\n' firefox  firefox 29.0+build1-0ubuntu0.13.10.3  

To only get the version string:

$ dpkg-query -W -f='${Version}\n' firefox  29.0+build1-0ubuntu0.13.10.3  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »