如何知道哪个包负责安装给定的程序

如何知道哪个包负责安装给定的程序

MEGA 摘要:当无法访问 GUI 互联网浏览器、没有手机等时,如何更轻松地搜索程序。在 Linux 中只有 CLI。

假设我正在使用 CentOS 7,并且正在寻找要安装的程序。我想安装“locate”命令。为此,我输入yum search locate。shell 会返回一个软件包列表。

mlocate.x86_64 : An utility for finding files by name
perl-File-ShareDir.noarch : Locate per-dist and per-module shared files
which.x86_64 : Displays where a particular program in your path is located

在这种情况下,我直观地知道 mlocate.x86_64 可能是我要找的,所以我通过它安装它,yum install mlocate.x86_64但是我遇到了很大的麻烦,因为搜索程序时得到的是一个巨大的软件包列表。例如:我安装了最小安装 centos 7。完成后,我搜索桌面环境 xfce yum search xfce。输出非常多,我甚至不知道这些包是什么。我知道 xfce 是一个“桌面环境”,所以我yum search xfce | grep dekstop。这给了我:

libxfce4util.i686 : Utility library for the Xfce4 desktop environment
libxfce4util.x86_64 : Utility library for the Xfce4 desktop environment
xfce4-power-manager.x86_64 : Power management for the Xfce desktop environment
exo.i686 : Application library for the Xfce desktop environment
exo.x86_64 : Application library for the Xfce desktop environment
xfdesktop.x86_64 : Desktop manager for the XFce Desktop Environment

唯一接近我想要的是:

xfdesktop.x86_64 : Desktop manager for the XFce Desktop Environment

但是我不确定。没有任何地方提到“Xfce 桌面环境”。它只是说它是该环境的桌面管理器。我不知道那是什么意思。也许那个特定的例子只是表明我很笨,但是我想安装的许多程序都遇到了这个问题。

我搜索一个 ssh 客户端:

[root@box-codeanywhere /]# yum search ssh | grep client
gsi-openssh-clients.x86_64 : SSH client applications with GSI authentication
libguac-client-ssh.i686 : SSH support for guacd
libguac-client-ssh.x86_64 : SSH support for guacd
ne7ssh.i686 : SSH Library is a Secure Shell client software written in C++
ne7ssh.x86_64 : SSH Library is a Secure Shell client software written in C++
openssh-clients.x86_64 : An open source SSH client applications
perl-Net-OpenSSH.noarch : Perl SSH client package implemented on top of OpenSSH
perl-Net-SSH-Perl.noarch : SSH (Secure Shell) client
dropbear.x86_64 : SSH2 server and client
perl-Net-SFTP-Foreign.noarch : SSH File Transfer Protocol client
putty.x86_64 : SSH, Telnet and Rlogin client
                            : clients and server

我怎么知道我需要安装哪个包...我经常遇到这个问题。看来我需要知道负责安装某个程序的包的确切名称字符串。我的问题是:当无法访问 GUI 互联网浏览器、我身上没有手机等时,如何更轻松地搜索程序。在 Linux 中只有 CLI。

答案1

搜索程序的工具是 apt-file,您可以按照以下方式安装:

# Install apt-file, which allows you to search
# for the package containing a file
sudo apt-get install apt-file

# Update the package/file mapping database
sudo apt-file update

如果您知道该程序的绝对路径,您可以搜索它:

$ apt-file search /usr/bin/locate

或者您可以搜索出现在路径中的程序:

# Search for "locate" at the end of a path
apt-file search --regexp '/locate$'

在输出中,只有一个包将指定位于标准 PATH 中的可执行文件,这暗示它可能是正确的。

您还可以了解有关该包的更多信息,以确保它看起来是正确的:

$ apt-cache show <package-name>

这将列出包中包含的所有程序并可作为验证。

Yum 还接受命令whatprovides(或provides)来搜索已安装或未安装的二进制文件:

yum whatprovides <path-to-file>

zypper 的搜索命令与 -f 选项一起使用时可以检查文件列表:

zypper se -f /usr/bin/locate

Pkgfile 可用作基于 pacman 系统的 pkgtools,提供与上述其他类似的搜索功能:

pkgfile -si /usr/bin/mysqldump

更多信息请参见:

相关内容