2

I'm always confused to get the version of software installed in Ubuntu. To prevent from full typing to get the version like <software> --version instead I always use something like <software> -V.

But the problem is that not for all software it works. For some I've to use <software> -v and for some, I've to use full --version to get the version.

For example

wget, gedit, nano, mysql`, etc all work with -V (Capital V)

but Php, Skype and may be others never worked with -V instead I've to use -v (small v) to get the version:

php -V
Usage: php [options] [-f] <file> [--] [args...]
   php [options] -r <code> [--] [args...]
   php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]
   php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]
   ...

php -v PHP 5.3.10-1ubuntu3.9 with Suhosin-Patch (cli) (built: Dec 12 2013 04:27:25) ...

Some work with both -v and -V like firefox. And some even don't work with either of -v or -V like totem, wine and google-chrome.

  • Why there is this much difference?
  • Since -V is always preferred to get the version of the software, why there is no any standard? or is there any standard that I don't know?
Milan
  • 172
Saurav Kumar
  • 14,916

4 Answers4

3

The correct way to get the version of system-installed software is to use your package manager tools!

--version is not a reliable way to do so, for several reasons:

  • Not all programs have executables. Libraries are a good example. You can't check your kernel version using linux --version, as there is no such command. Or your video driver version.

  • Not all executables have command-line arguments. Most do, but GUI programs don't need to, and some don't.

  • --version, as any command-line argument, is application-dependent. It depends on the developer to implement it, and there is no "standard" per-se, merely a convention. As you've noticed with -v|-V, it is not consistent. Even --help is not universal.

  • The format output of --version is not consistent either. Some print a single line, some print several. Some print the version number only, some print the program name too.

That said, there is a standard, consistent way to get the installed version of any software in your system: ask the system, not the sofware!

Thanks to its Debian heritage, Ubuntu has a powerful package management system called apt (actually, dpkg). It controls installed packages, its dependencies, available repositories, and versions.

There are several package-management tools and front-ends you can use to query your installed packages. Here are some that display the version:

  • apt-cache policy <package>

  • dpkg --list <package> (you can use wildcards!)

And if you don't know what package a given command belongs to, you can find out in several ways:

  • apt-cache search '<name>'

  • apt-file search '<path>'

And the output is always consistent, reliable, standard, because you're not asking individual software made by distinct developers, you're querying your system about its status.

As an example, here's the result of a search of all the commands your mentioned in a single output:

$ dpkg --list wget gedit nano mysql-server skype php? firefox totem wine google-chrome*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                       Version                    Description
+++-==========================-==========================-====================================================================
ii  firefox                    42.0+build2-0ubuntu0.12.04 Safe and easy web browser from Mozilla
ii  gedit                      3.4.1-0ubuntu1             official text editor of the GNOME desktop environment
ii  google-chrome-stable       46.0.2490.80-1             The web browser from Google
ii  mysql-server               5.5.46-0ubuntu0.12.04.2    MySQL database server (metapackage depending on the latest version)
ii  nano                       2.2.6-1                    small, friendly text editor inspired by Pico
ii  php5                       5.3.10-1ubuntu3.21         server-side, HTML-embedded scripting language (metapackage)
ii  skype                      4.3.0.37-0ubuntu0.12.04.1  client for Skype VOIP and instant messaging service
ii  totem                      3.0.1-0ubuntu21.1          Simple media player for the GNOME desktop based on GStreamer
ii  wget                       1.13.4-2ubuntu1.2          retrieves files from the web
ii  wine                       1.4-0ubuntu4.1             Microsoft Windows Compatibility Layer (meta-package)
MestreLion
  • 20,086
  • 2
    Agreed.. Ask the system, Not the software! – Saurav Kumar Nov 11 '15 at 07:06
  • Great answer. Thanks! But, I have one query: while finding a version using --version for Google chrome, I can use either google-chrome --version or google-chrome-stable --version. Both give the same result. However, in the case of dpkg --list, why does only dpkg --list google-chrome-stable work? For dpkg --list google-chrome, I'm getting dpkg-query: no packages found matching google-chrome error!! – Milan Sep 19 '20 at 01:33
  • 1
    @Milan: Because Google Chrome (the software) package is google-chrome-stable, and that package contains two executables, /usr/bin/google-chrome-stable and /usr/bin/google-chrome (and both are symlinks which which ultimately point to /opt/google/chrome/google-chrome). So you can either ask the software invoking their executables, or ask dpkg using its package name. – MestreLion Sep 19 '20 at 19:38
  • @MestreLion Thanks a lot again for your reply. Got your point. Just to understand more, I noticed that /usr/bin/google-chrome is a soft link to /etc/alternatives/google-chrome which is a soft link to /usr/bin/google-chrome-stable. On the other hand /usr/bin/google-chrome-stable is a soft link to /opt/google/chrome/google-chrome. So, where does Linux stores the package name? I mean how does it confirms whether the package name is google-chrome-stable or google-chrome? – Milan Sep 21 '20 at 17:53
  • 1
    @Milan: How does it confirms the package name? In a way, it doesn't. All Ubuntu (actually dpkg) knows is that is has several packages installed, google-chrome-stable being one of them. That package contains a bunch of files, and executables, including /opt/google/chrome/google-chrome, and the install script creates the soft links. dpkg does not care if the names of the executables match the package name. It's just a bunch of files. – MestreLion Sep 23 '20 at 01:34
  • 1
    @Milan: you might ask dpgk "Which files does package X contains?" (dpkg --listfiles <package>), or "Which package does file Y belong to?" (dpkg --search <file>), both of which are irrelevant for executing a given software once its package is installed. – MestreLion Sep 23 '20 at 01:43
  • 1
    Lastly: /etc/alternatives is a mechanism for choosing between implementations of a given name, using soft links for that. It deals with files, not packages. If you have several text editors, like nano and vi. which one will be editor command? Or several Java versions, from different vendors, which one will be invoked when you simply type java? That's what the alternative system is for. So Google Chrome is creating an alternative too, maybe to allow co-existence of distinct chrome versions (stable, unstable, nightly, beta, long-term), one being your main google-chrome – MestreLion Sep 23 '20 at 01:58
  • @MestreLion: thank you so much again for your time and for such detailed replies. I appreciate that. And sorry in advance but now, I got other questions: you mentioned "All Ubuntu (actually dpkg) knows is that is has several packages installed, google-chrome-stable being one of them." But does Ubuntu (or dpkg) store the name of installed packages in any local file...I mean htop displays all the meaningful information by reading from various system files and doing some sort of calculation on it, right? So, does dpkg do anything like that? Sorry, if the question is too basic/off-topic! – Milan Oct 05 '20 at 11:04
  • @MestreLion: one more thing: thank you so much for sharing these very useful commands: dpkg --listfiles <package> & dpkg --search <file>. However, why did you say "both of which are irrelevant for executing a given software once its package is installed."? If possible, could you please elaborate a little bit more on that or share any useful articles/links where I can read more by myself? – Milan Oct 05 '20 at 11:09
  • @MestreLion: I didn't know about /etc/alternatives before. Thanks for sharing that one as well! You said "It deals with files, not packages." but, if I want to update the soft link manually then is it possible? e.g. right now, editor is pointing to nano by editor -> /bin/nano* but if I want to change to gedit then is there any dpkg command whose output I can use to update the soft link for editor in /etc/alternatives? I mean there are so many files for gedit (output of dpkg --listfiles gedit), so, how can I decide which file to use to update that soft link? Thanks again:) – Milan Oct 05 '20 at 11:19
  • 1
    @Milan: all great questions, all off-topic to this one. Create new questions, post me their links here and I'll gladly answer them all – MestreLion Oct 27 '20 at 14:49
  • Thank you so much @MestreLion for your response. Sure, that's a good idea. I would create new question(s) and post the links here! Again, I appreciate your initiative and your time. – Milan Oct 28 '20 at 21:17
1

Those are verbose options related to each application so some apps used the -V others use -v others both or just --version. There is no general rule for naming convention.

what i mean to say is those options don't have a standard so you may find option -X in some app do the same as -R in other ...

Maythux
  • 84,289
1

The standard is:

app --version

-v or -V is only (not generally speaking) the abbreviated form for --version. You will never see in a man page something like:

-v
    Print version...

or:

-V
    Print version...

but you will see all the time these two options, the abbreviated form (if this exists) and the standard form, together. Something like:

-v, --version
    Print version...

or:

-V, --version
    Print version...

But this depends only by developers how they want to implement their applications. For example -v is used in some cases as the abbreviated form for --verbose (see man wget), or for --invert-match (see man grep) a.o., or in other cases as stand alone (see man awk or man ps).

Radu Rădeanu
  • 169,590
0

It typically ends up being caused by an option called "verbosity". Verbosity runs a program and prints as much information as possible to the terminal from which it was called.

Some programs, however, don't support verbose mode or don't run in a way that would require any form of verbosity, so they will spit out the help string. Others will treat -v and -V equally.

ExplodingKittens
  • 882
  • 1
  • 9
  • 21