皇上,还记得我吗?我就是1999年那个Linux伊甸园啊-----24小时滚动更新开源资讯,全年无休!

RPM 包初窥

也许,Fedora 社区追求其促进自由和开源的软件及内容的使命的最著名的方式就是开发 Fedora 软件发行版了。因此,我们将很大一部分的社区资源用于此任务也就不足为奇了。这篇文章总结了这些软件是如何“打包”的,以及使之成为可能的基础工具,如 rpm 之类。

RPM:最小的软件单元

可供用户选择的“版本”和“风味版”(spins / labs / silverblue)其实非常相似。它们都是由各种软件组成的,这些软件经过混合和搭配,可以很好地协同工作。它们之间的不同之处在于放入其中的具体工具不同。这种选择取决于它们所针对的用例。所有这些的“版本”和“风味版”基本组成单位都是 RPM 软件包文件。

RPM 文件是类似于 ZIP 文件或 tarball 的存档文件。实际上,它们使用了压缩来减小存档文件的大小。但是,除了文件之外,RPM 存档中还包含有关软件包的元数据。可以使用 rpm 工具查询:

  1. $ rpm -q fpaste
  2. fpaste-0.3.9.2-2.fc30.noarch
  3. $ rpm -qi fpaste
  4. Name : fpaste
  5. Version : 0.3.9.2
  6. Release : 2.fc30
  7. Architecture: noarch
  8. Install Date: Tue 26 Mar 2019 08:49:10 GMT
  9. Group : Unspecified
  10. Size : 64144
  11. License : GPLv3+
  12. Signature : RSA/SHA256, Thu 07 Feb 2019 15:46:11 GMT, Key ID ef3c111fcfc659b9
  13. Source RPM : fpaste-0.3.9.2-2.fc30.src.rpm
  14. Build Date : Thu 31 Jan 2019 20:06:01 GMT
  15. Build Host : buildhw-07.phx2.fedoraproject.org
  16. Relocations : (not relocatable)
  17. Packager : Fedora Project
  18. Vendor : Fedora Project
  19. URL : https://pagure.io/fpaste
  20. Bug URL : https://bugz.fedoraproject.org/fpaste
  21. Summary : A simple tool for pasting info onto sticky notes instances
  22. Description :
  23. It is often useful to be able to easily paste text to the Fedora
  24. Pastebin at http://paste.fedoraproject.org and this simple script
  25. will do that and return the resulting URL so that people may
  26. examine the output. This can hopefully help folks who are for
  27. some reason stuck without X, working remotely, or any other
  28. reason they may be unable to paste something into the pastebin
  29. $ rpm -ql fpaste
  30. /usr/bin/fpaste
  31. /usr/share/doc/fpaste
  32. /usr/share/doc/fpaste/README.rst
  33. /usr/share/doc/fpaste/TODO
  34. /usr/share/licenses/fpaste
  35. /usr/share/licenses/fpaste/COPYING
  36. /usr/share/man/man1/fpaste.1.gz

安装 RPM 软件包后,rpm 工具可以知道具体哪些文件被添加到了系统中。因此,删除该软件包也会删除这些文件,并使系统保持一致状态。这就是为什么要尽可能地使用 rpm 安装软件,而不是从源代码安装软件的原因。

依赖关系

如今,完全独立的软件已经非常罕见。甚至 fpaste,连这样一个简单的单个文件的 Python 脚本,都需要安装 Python 解释器。因此,如果系统未安装 Python(几乎不可能,但有可能),则无法使用 fpaste。用打包者的术语来说,“Python 是 fpaste 的运行时依赖项。”

构建 RPM 软件包时(本文不讨论构建 RPM 的过程),生成的归档文件中包括了所有这些元数据。这样,与 RPM 软件包归档文件交互的工具就知道必须要安装其它的什么东西,以便 fpaste 可以正常工作:

  1. $ rpm -q --requires fpaste
  2. /usr/bin/python3
  3. python3
  4. rpmlib(CompressedFileNames) <= 3.0.4-1
  5. rpmlib(FileDigests) <= 4.6.0-1
  6. rpmlib(PayloadFilesHavePrefix) <= 4.0-1
  7. rpmlib(PayloadIsXz) <= 5.2-1
  8. $ rpm -q --provides fpaste
  9. fpaste = 0.3.9.2-2.fc30
  10. $ rpm -qi python3
  11. Name : python3
  12. Version : 3.7.3
  13. Release : 3.fc30
  14. Architecture: x86_64
  15. Install Date: Thu 16 May 2019 18:51:41 BST
  16. Group : Unspecified
  17. Size : 46139
  18. License : Python
  19. Signature : RSA/SHA256, Sat 11 May 2019 17:02:44 BST, Key ID ef3c111fcfc659b9
  20. Source RPM : python3-3.7.3-3.fc30.src.rpm
  21. Build Date : Sat 11 May 2019 01:47:35 BST
  22. Build Host : buildhw-05.phx2.fedoraproject.org
  23. Relocations : (not relocatable)
  24. Packager : Fedora Project
  25. Vendor : Fedora Project
  26. URL : https://www.python.org/
  27. Bug URL : https://bugz.fedoraproject.org/python3
  28. Summary : Interpreter of the Python programming language
  29. Description :
  30. Python is an accessible, high-level, dynamically typed, interpreted programming
  31. language, designed with an emphasis on code readability.
  32. It includes an extensive standard library, and has a vast ecosystem of
  33. third-party libraries.
  34. The python3 package provides the "python3" executable: the reference
  35. interpreter for the Python language, version 3.
  36. The majority of its standard library is provided in the python3-libs package,
  37. which should be installed automatically along with python3.
  38. The remaining parts of the Python standard library are broken out into the
  39. python3-tkinter and python3-test packages, which may need to be installed
  40. separately.
  41. Documentation for Python is provided in the python3-docs package.
  42. Packages containing additional libraries for Python are generally named with
  43. the "python3-" prefix.
  44. $ rpm -q --provides python3
  45. python(abi) = 3.7
  46. python3 = 3.7.3-3.fc30
  47. python3(x86-64) = 3.7.3-3.fc30
  48. python3.7 = 3.7.3-3.fc30
  49. python37 = 3.7.3-3.fc30

解决 RPM 依赖关系

虽然 rpm 知道每个归档文件所需的依赖关系,但不知道在哪里找到它们。这是设计使然:rpm 仅适用于本地文件,必须具体告知它们的位置。因此,如果你尝试安装单个 RPM 软件包,则 rpm 找不到该软件包的运行时依赖项时就会出错。本示例尝试安装从 Fedora 软件包集中下载的软件包:

  1. $ ls
  2. python3-elephant-0.6.2-3.fc30.noarch.rpm
  3. $ rpm -qpi python3-elephant-0.6.2-3.fc30.noarch.rpm
  4. Name : python3-elephant
  5. Version : 0.6.2
  6. Release : 3.fc30
  7. Architecture: noarch
  8. Install Date: (not installed)
  9. Group : Unspecified
  10. Size : 2574456
  11. License : BSD
  12. Signature : (none)
  13. Source RPM : python-elephant-0.6.2-3.fc30.src.rpm
  14. Build Date : Fri 14 Jun 2019 17:23:48 BST
  15. Build Host : buildhw-02.phx2.fedoraproject.org
  16. Relocations : (not relocatable)
  17. Packager : Fedora Project
  18. Vendor : Fedora Project
  19. URL : http://neuralensemble.org/elephant
  20. Bug URL : https://bugz.fedoraproject.org/python-elephant
  21. Summary : Elephant is a package for analysis of electrophysiology data in Python
  22. Description :
  23. Elephant - Electrophysiology Analysis Toolkit Elephant is a package for the
  24. analysis of neurophysiology data, based on Neo.
  25. $ rpm -qp --requires python3-elephant-0.6.2-3.fc30.noarch.rpm
  26. python(abi) = 3.7
  27. python3.7dist(neo) >= 0.7.1
  28. python3.7dist(numpy) >= 1.8.2
  29. python3.7dist(quantities) >= 0.10.1
  30. python3.7dist(scipy) >= 0.14.0
  31. python3.7dist(six) >= 1.10.0
  32. rpmlib(CompressedFileNames) <= 3.0.4-1
  33. rpmlib(FileDigests) <= 4.6.0-1
  34. rpmlib(PartialHardlinkSets) <= 4.0.4-1
  35. rpmlib(PayloadFilesHavePrefix) <= 4.0-1
  36. rpmlib(PayloadIsXz) <= 5.2-1
  37. $ sudo rpm -i ./python3-elephant-0.6.2-3.fc30.noarch.rpm
  38. error: Failed dependencies:
  39. python3.7dist(neo) >= 0.7.1 is needed by python3-elephant-0.6.2-3.fc30.noarch
  40. python3.7dist(quantities) >= 0.10.1 is needed by python3-elephant-0.6.2-3.fc30.noarch

理论上,你可以下载 python3-elephant 所需的所有软件包,并告诉 rpm 它们都在哪里,但这并不方便。如果 python3-neo 和 python3-quantities 还有其它的运行时要求怎么办?很快,这种“依赖链”就会变得相当复杂。

存储库

幸运的是,有了 dnf 和它的朋友们,可以帮助解决此问题。与 rpm 不同,dnf 能感知到存储库。存储库是程序包的集合,带有告诉 dnf 这些存储库包含什么内容的元数据。所有 Fedora 系统都带有默认启用的默认 Fedora 存储库:

  1. $ sudo dnf repolist
  2. repo id              repo name                             status
  3. fedora               Fedora 30 - x86_64                    56,582
  4. fedora-modular       Fedora Modular 30 - x86_64               135
  5. updates              Fedora 30 - x86_64 - Updates           8,573
  6. updates-modular      Fedora Modular 30 - x86_64 - Updates     138
  7. updates-testing      Fedora 30 - x86_64 - Test Updates      8,458

在 Fedora 快速文档中有这些存储库以及如何管理它们的更多信息。

dnf 可用于查询存储库以获取有关它们包含的软件包信息。它还可以在这些存储库中搜索软件,或从中安装/卸载/升级软件包:

  1. $ sudo dnf search elephant
  2. Last metadata expiration check: 0:05:21 ago on Sun 23 Jun 2019 14:33:38 BST.
  3. ============================================================================== Name & Summary Matched: elephant ==============================================================================
  4. python3-elephant.noarch : Elephant is a package for analysis of electrophysiology data in Python
  5. python3-elephant.noarch : Elephant is a package for analysis of electrophysiology data in Python
  6. $ sudo dnf list \*elephant\*
  7. Last metadata expiration check: 0:05:26 ago on Sun 23 Jun 2019 14:33:38 BST.
  8. Available Packages
  9. python3-elephant.noarch 0.6.2-3.fc30 updates-testing
  10. python3-elephant.noarch 0.6.2-3.fc30 updates

安装依赖项

现在使用 dnf 安装软件包时,它将解决所有必需的依赖项,然后调用 rpm 执行该事务操作:

  1. $ sudo dnf install python3-elephant
  2. Last metadata expiration check: 0:06:17 ago on Sun 23 Jun 2019 14:33:38 BST.
  3. Dependencies resolved.
  4. ==============================================================================================================================================================================================
  5. Package Architecture Version Repository Size
  6. ==============================================================================================================================================================================================
  7. Installing:
  8. python3-elephant noarch 0.6.2-3.fc30 updates-testing 456 k
  9. Installing dependencies:
  10. python3-neo noarch 0.8.0-0.1.20190215git49b6041.fc30 fedora 753 k
  11. python3-quantities noarch 0.12.2-4.fc30 fedora 163 k
  12. Installing weak dependencies:
  13. python3-igor noarch 0.3-5.20150408git2c2a79d.fc30 fedora 63 k
  14. Transaction Summary
  15. ==============================================================================================================================================================================================
  16. Install 4 Packages
  17. Total download size: 1.4 M
  18. Installed size: 7.0 M
  19. Is this ok [y/N]: y
  20. Downloading Packages:
  21. (1/4): python3-igor-0.3-5.20150408git2c2a79d.fc30.noarch.rpm 222 kB/s | 63 kB 00:00
  22. (2/4): python3-elephant-0.6.2-3.fc30.noarch.rpm 681 kB/s | 456 kB 00:00
  23. (3/4): python3-quantities-0.12.2-4.fc30.noarch.rpm 421 kB/s | 163 kB 00:00
  24. (4/4): python3-neo-0.8.0-0.1.20190215git49b6041.fc30.noarch.rpm 840 kB/s | 753 kB 00:00
  25. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  26. Total 884 kB/s | 1.4 MB 00:01
  27. Running transaction check
  28. Transaction check succeeded.
  29. Running transaction test
  30. Transaction test succeeded.
  31. Running transaction
  32. Preparing : 1/1
  33. Installing : python3-quantities-0.12.2-4.fc30.noarch 1/4
  34. Installing : python3-igor-0.3-5.20150408git2c2a79d.fc30.noarch 2/4
  35. Installing : python3-neo-0.8.0-0.1.20190215git49b6041.fc30.noarch 3/4
  36. Installing : python3-elephant-0.6.2-3.fc30.noarch 4/4
  37. Running scriptlet: python3-elephant-0.6.2-3.fc30.noarch 4/4
  38. Verifying : python3-elephant-0.6.2-3.fc30.noarch 1/4
  39. Verifying : python3-igor-0.3-5.20150408git2c2a79d.fc30.noarch 2/4
  40. Verifying : python3-neo-0.8.0-0.1.20190215git49b6041.fc30.noarch 3/4
  41. Verifying : python3-quantities-0.12.2-4.fc30.noarch 4/4
  42. Installed:
  43. python3-elephant-0.6.2-3.fc30.noarch python3-igor-0.3-5.20150408git2c2a79d.fc30.noarch python3-neo-0.8.0-0.1.20190215git49b6041.fc30.noarch python3-quantities-0.12.2-4.fc30.noarch
  44. Complete!

请注意,dnf 甚至还安装了python3-igor,而它不是 python3-elephant 的直接依赖项。

DnfDragora:DNF 的一个图形界面

尽管技术用户可能会发现 dnf 易于使用,但并非所有人都这样认为。Dnfdragora 通过为 dnf 提供图形化前端来解决此问题。

dnfdragora (version 1.1.1-2 on Fedora 30) listing all the packages installed on a system.

dnfdragora (version 1.1.1-2 on Fedora 30) listing all the packages installed on a system.

从上面可以看到,dnfdragora 似乎提供了 dnf 的所有主要功能。

Fedora 中还有其他工具也可以管理软件包,GNOME 的“软件Software”和“发现Discover”就是其中两个。GNOME “软件”仅专注于图形应用程序。你无法使用这个图形化前端来安装命令行或终端工具,例如 htop 或 weechat。但是,GNOME “软件”支持安装 dnf 所不支持的 Flatpak 和 Snap 应用程序。它们是针对不同目标受众的不同工具,因此提供了不同的功能。

这篇文章仅触及到了 Fedora 软件的生命周期的冰山一角。本文介绍了什么是 RPM 软件包,以及使用 rpm 和 dnf 的主要区别。

在以后的文章中,我们将详细介绍:

  • 创建这些程序包所需的过程
  • 社区如何测试它们以确保它们正确构建
  • 社区用来将其给到社区用户的基础设施

via: https://fedoramagazine.org/rpm-packages-explained/

作者:Ankur Sinha FranciscoD 选题:lujun9972 译者:wxy 校对:wxy

本文由 LCTT 原创编译,Linux中国 荣誉推出

转自 https://linux.cn/article-11452-1.html

分享到:更多 ()