106

I need to determine which version of GTK+ is installed on Ubuntu

Man does not seem to help

iain
  • 5,660
  • 1
  • 30
  • 51
Craig Angus
  • 22,784
  • 18
  • 55
  • 63

14 Answers14

84

This suggestion will tell you which minor version of 2.0 is installed. Different major versions will have different package names because they can co-exist on the system (in order to support applications built with older versions).

Even for development files, which normally would only let you have one version on the system, you can have a version of gtk 1.x and a version of gtk 2.0 on the same system (the include files are in directories called gtk-1.2 or gtk-2.0).

So in short there isn't a simple answer to "what version of GTK is on the system". But...

Try something like:

dpkg -l libgtk* | grep -e '^i' | grep -e 'libgtk-*[0-9]'

to list all the libgtk packages, including -dev ones, that are on your system. dpkg -l will list all the packages that dpkg knows about, including ones that aren't currently installed, so I've used grep to list only ones that are installed (line starts with i).

Alternatively, and probably better if it's the version of the headers etc that you're interested in, use pkg-config:

pkg-config --modversion gtk+

will tell you what version of GTK 1.x development files are installed, and

pkg-config --modversion gtk+-2.0

will tell you what version of GTK 2.0. The old 1.x version also has its own gtk-config program that does the same thing. Similarly, for GTK+ 3:

pkg-config --modversion gtk+-3.0
Community
  • 1
  • 1
Mark Baker
  • 5,588
  • 2
  • 27
  • 25
  • 1
    Any suggestion for windows ? how to find installed gtk version on windows ? – avimehenwal May 02 '13 at 12:47
  • The pkg-config program is part of the windows installation. So writing pkg-config --modversion gtk+-2.0 in the command line should work. – pepan Nov 23 '13 at 09:35
  • 1
    Pretty sure the `libgtk*` in `dpkg -l libgtk*` has to be enclosed in single quotes (`dpkg -l 'libgtk*'`) to prevent wildcard expansion at the shell level. – sevko Jul 24 '15 at 16:01
  • If there are no glob matches, and there probably aren't here, then it wil be passed to the command unexpanded, so this will work. But it would indeed be safer to quote it. – Mark Baker Oct 17 '16 at 10:49
  • To check gtkmm try: `pkg-config --modversion gtkmm-3.0` – Melroy van den Berg Apr 04 '21 at 22:19
  • pkg-config --modversion gtk4 – Adam Nov 11 '22 at 17:56
65

This isn't so difficult.

Just check your gtk+ toolkit utilities version from terminal:

gtk-launch --version
survivor303
  • 752
  • 5
  • 7
28

get GTK3 version:

dpkg -s libgtk-3-0|grep '^Version'

or just version number

dpkg -s libgtk-3-0|grep '^Version' | cut -d' ' -f2-
Arnab Nandy
  • 6,472
  • 5
  • 44
  • 50
Dr Casper Black
  • 7,350
  • 1
  • 26
  • 33
26

You can use this command:

$ dpkg -s libgtk2.0-0|grep '^Version'
Lukas Würzburger
  • 6,543
  • 7
  • 41
  • 75
Torsten Marek
  • 83,780
  • 21
  • 91
  • 98
  • 1
    This was getting minor versions of GTK+ 2, but GTK+ 3 has been out for years now and GTK+ 4 in on the way. – liberforce Dec 05 '17 at 16:50
9

You could also just compile the following program and run it on your machine.

#include <gtk/gtk.h>
#include <glib/gprintf.h>

int main(int argc, char *argv[])
{
    /* Initialize GTK */
    gtk_init (&argc, &argv);

    g_printf("%d.%d.%d\n", gtk_major_version, gtk_minor_version, gtk_micro_version);
    return(0);
}

compile with ( assuming above source file is named version.c):

gcc version.c -o version `pkg-config --cflags --libs gtk+-2.0`

When you run this you will get some output. On my old embedded device I get the following:

[root@n00E04B3730DF n2]# ./version 
2.10.4
[root@n00E04B3730DF n2]#
Chimera
  • 5,884
  • 7
  • 49
  • 81
  • 2
    If I compile as you say, I get 2.24.27. If I compile with `--libs gtk+-3.0` instead, I get 3.10.8. This just seems to tell me that I have development files for both, but not which I'm using at the moment. – tsbertalan Sep 03 '16 at 00:18
  • gtkv.c:1:21: fatal error: gtk/gtk.h: No such file or directory – niken Dec 21 '16 at 21:10
  • @tsbertalan "using at the moment" depends upon what version of GTK your various apps are linked against. – Chimera Sep 27 '17 at 15:40
  • it does not compile on gtk4. gcc $(pkg-config --cflags gtk4) w.c $(pkg-config --libs gtk4) w.c: In function ‘main’: w.c:10:5: error: too many arguments to function ‘gtk_init’ – Adam Nov 11 '22 at 17:50
7

Try,

apt-cache policy libgtk2.0-0 libgtk-3-0 

or,

dpkg -l libgtk2.0-0 libgtk-3-0
Arnab Nandy
  • 6,472
  • 5
  • 44
  • 50
4

I think a distribution-independent way is:

gtk-config --version

Xqj37
  • 77
  • 1
  • 3
    While gtk-config is distribution independent, it only works for GTK 1.x. The correct way for newer versions is to use pkg-config, as I said in my answer. – Mark Baker Sep 25 '08 at 15:09
3

You can also just open synaptic and search for libgtk, it will show you exactly which lib is installed.

Luka Marinko
  • 1,693
  • 2
  • 11
  • 14
3

Because apt-cache policy will list all the matches available, even if not installed, I would suggest using this command for a more manageable shortlist of GTK-related packages installed on your system:

apt list --installed libgtk*
stragu
  • 1,051
  • 9
  • 15
2

Try:

 dpkg-query -W libgtk-3-bin
ThorSummoner
  • 16,657
  • 15
  • 135
  • 147
2

This will get the version of the GTK libraries for GTK 2, 3, and 4.

dpkg -l | egrep "libgtk(2.0-0|-3-0|-4)"

As major versions are parallel installable, you may have several of them on your system, which is my case, so the above command returns this on my Ubuntu Trusty system:

ii  libgtk-3-0:amd64                                      3.10.8-0ubuntu1.6                                   amd64        GTK+ graphical user interface library
ii  libgtk2.0-0:amd64                                     2.24.23-0ubuntu1.4                                  amd64        GTK+ graphical user interface library

This means I have GTK+ 2.24.23 and 3.10.8 installed.

If what you want is the version of the development files, use:

  • pkg-config --modversion gtk+-2.0 for GTK 2
  • pkg-config --modversion gtk+-3.0 for GTK 3
  • pkg-config --modversion gtk4 for GTK 4

(This changed because the + from GTK+ was dropped a while ago.)

liberforce
  • 11,189
  • 37
  • 48
1

To make the answer more general than Ubuntu (I have Redhat):

gtk is usually installed under /usr, but possibly in other locations. This should be visible in environment variables. Check with

env | grep gtk

Then try to find where your gtk files are stored. For example, use locate and grep.

locate gtk | grep /usr/lib

In this way, I found /usr/lib64/gtk-2.0, which contains the subdirectory 2.10.0, which contains many .so library files. My conclusion is that I have gtk+ version 2.10. This is rather consistent with the rpm command on Redhat: rpm -qa | grep gtk2, so I think my conclusion is right.

Helge
  • 145
  • 9
1

To compile and link a GTK program with pkg-config, we need the library name instead of the actual version number. For example, the following command compiles and links a GTK program that uses the GTK4 library:

gcc -o program program.c `pkg-config --cflags --libs gtk4`

To obtain the library name for GTK, use the following command:

pkg-config --list-all | grep gtk
maruf
  • 599
  • 3
  • 6
  • 22
0

I think the easiest way is to use rpm -q gtk4 and then replace the 4 with a 3 if you want the GTK3 version.

Stephan
  • 345
  • 2
  • 14