Linux 你如何知道 Ubuntu 上安装了哪个版本的 GTK+?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/126141/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 16:31:16  来源:igfitidea点击:

How do you find out which version of GTK+ is installed on Ubuntu?

linuxubuntugtkgnome

提问by Craig Angus

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

我需要确定在 Ubuntu 上安装了哪个版本的 GTK+

Man does not seem to help

男人似乎没有帮助

采纳答案by Mark Baker

This suggestionwill 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).

这个建议会告诉你安装的是哪个次要版本的 2.0。不同的主要版本会有不同的包名,因为它们可以在系统上共存(以支持使用旧版本构建的应用程序)。

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).

即使对于通常只允许您在系统上拥有一个版本的开发文件,您也可以在同一系统上拥有一个 gtk 1.x 版本和一个 gtk 2.0 版本(包含文件位于名为 gtk-1.2 或gtk-2.0)。

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

所以简而言之,“系统上的 GTK 版本是什么”并没有一个简单的答案。但...

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 -lwill 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).

列出系统上的所有 libgtk 包,包括 -dev 包。dpkg -l将列出 dpkg 知道的所有软件包,包括当前未安装的软件包,因此我使用 grep 仅列出已安装的软件包(行以 i 开头)。

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

或者,如果您感兴趣的标头等版本可能更好,请使用 pkg-config:

pkg-config --modversion gtk+

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

会告诉你安装了哪个版本的 GTK 1.x 开发文件,以及

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:

会告诉你什么版本的 GTK 2.0。旧的 1.x 版本也有自己的 gtk-config 程序来做同样的事情。同样,对于 GTK+ 3:

pkg-config --modversion gtk+-3.0

回答by Torsten Marek

$ dpkg -s libgtk2.0-0|grep '^Version'

回答by Xqj37

I think a distribution-independent way is:

我认为与分布无关的方式是:

gtk-config --version

gtk-config --version

回答by Luka Marinko

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

您也可以打开突触并搜索 libgtk,它会准确显示安装了哪个 lib。

回答by Dr Casper Black

get GTK3 version:

获取 GTK3 版本:

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

or just version number

或者只是版本号

dpkg -s libgtk-3-0|grep '^Version' | cut -d' ' -f2-

回答by Helge

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

为了使答案比 Ubuntu 更通用(我有 Redhat):

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

gtk 通常安装在 /usr 下,但也可能安装在其他位置。这应该在环境变量中可见。检查

env | grep gtk

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

然后尝试查找您的 gtk 文件的存储位置。例如,使用locate和 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.

这样,我找到了/usr/lib64/gtk-2.0,里面包含了子目录2.10.0,里面有很多.so库文件。我的结论是我有 gtk+ 2.10 版。这与 Redhat: 上的 rpm 命令相当一致rpm -qa | grep gtk2,所以我认为我的结论是正确的。

回答by Chimera

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):

编译(假设上述源文件名为 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]#

回答by Максим Шатов

Try,

尝试,

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

or,

或者,

dpkg -l libgtk2.0-0 libgtk-3-0

回答by ThorSummoner

Try:

尝试:

 dpkg-query -W libgtk-3-bin

回答by liberforce

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

这将获得 GTK+ 2 和 GTK+ 3 的 GTK+ 库版本。

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

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

由于主要版本是可并行安装的,您的系统上可能同时安装了这两个版本,这就是我的情况,因此上述命令在我的 Ubuntu Trusty 系统上返回:

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.

这意味着我安装了 GTK+ 2.24.23 和 3.10.8。

If what you want is the version of the development files, use pkg-config --modversion gtk+-3.0for example for GTK+ 3. To extend that to the different major versions of GTK+, with some sed magic, this gives:

如果您想要的是开发文件的版本,pkg-config --modversion gtk+-3.0例如使用 GTK+ 3。为了将其扩展到 GTK+ 的不同主要版本,使用一些 sed 魔法,这给出:

pkg-config --list-all | sed -ne 's/\(gtk+-[0-9]*.0\).*//p' | xargs pkg-config --modversion