CentOS系统自动下载RPM包及其所有依赖的包

前几天我尝试去创建一个仅包含我们经常在 CentOS 7 下使用的软件的本地仓库。当然,我们可以使用 curl 或者 wget 下载任何软件包,然而这些命令并不能下载要求的依赖软件包。你必须去花一些时间而且手动的去寻找和下载被安装的软件所依赖的软件包。然而,我们并不是必须这样。在这个简短的教程中,我将会带领你以两种方式下载软件包及其所有依赖包。我已经在 CentOS 7 下进行了测试,不过这些相同的步骤或许在其他基于 RPM 管理系统的发行版上也可以工作,例如 RHEL,Fedora 和 Scientific Linux。

方法1利用"Downloadonly"插件下载 RPM 软件包及其所有依赖包

我们可以通过 yum 命令的 “Downloadonly” 插件下载 RPM 软件包及其所有依赖包, 为了安装 Downloadonly 插件,以 root 身份运行以下命令:

yum install yum-plugin-downloadonly  

现在,运行以下命令去下载一个 RPM 软件包

yum install --downloadonly <package-name>

默认情况下,这个命令将会下载并把软件包保存到 /var/cache/yum/ 的 rhel-{arch}-channel/packageslocation 目录,不过,你也可以下载和保存软件包到任何位置,你可以通过 –downloaddir 选项来指定。

yum install --downloadonly --downloaddir=<directory> <package-name>

例子:

yum install --downloadonly --downloaddir=/root/mypackages/  nginx

终端输出:

Loaded plugins: fastestmirror
base                                                                                                                                                                                                         | 3.6 kB  00:00:00     
epel/x86_64/metalink                                                                                                                                                                                         | 5.7 kB  00:00:00     
epel                                                                                                                                                                                                         | 4.7 kB  00:00:00     
extras                                                                                                                                                                                                       | 3.4 kB  00:00:00     
updates                                                                                                                                                                                                      | 3.4 kB  00:00:00     
(1/3): updates/7/x86_64/primary_db                                                                                                                                                                           | 3.6 MB  00:00:01     
(2/3): epel/x86_64/updateinfo                                                                                                                                                                                | 848 kB  00:00:02     
(3/3): epel/x86_64/primary_db                                                                                                                                                                                | 6.1 MB  00:03:08     
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * epel: mirrors.ustc.edu.cn
 * extras: mirrors.cn99.com
 * updates: mirrors.cn99.com
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.12.2-1.el7 will be installed
--> Processing Dependency: nginx-all-modules = 1:1.12.2-1.el7 for package: 1:nginx-1.12.2-1.el7.x86_64
--> Processing Dependency: nginx-filesystem = 1:1.12.2-1.el7 for package: 1:nginx-1.12.2-1.el7.x86_64
--> Processing Dependency: libcrypto.so.10(OPENSSL_1.0.2)(64bit) for package: 1:nginx-1.12.2-1.el7.x86_64
--> Processing Dependency: nginx-filesystem for package: 1:nginx-1.12.2-1.el7.x86_64
--> Processing Dependency: libprofiler.so.0()(64bit) for package: 1:nginx-1.12.2-1.el7.x86_64
--> Running transaction check
---> Package gperftools-libs.x86_64 0:2.4-8.el7 will be installed
--> Processing Dependency: libunwind.so.8()(64bit) for package: gperftools-libs-2.4-8.el7.x86_64
---> Package nginx-all-modules.noarch 1:1.12.2-1.el7 will be installed
--> Processing Dependency: nginx-mod-http-geoip = 1:1.12.2-1.el7 for package: 1:nginx-all-modules-1.12.2-1.el7.noarch
--> Processing Dependency: nginx-mod-http-image-filter = 1:1.12.2-1.el7 for package: 1:nginx-all-modules-1.12.2-1.el7.noarch
--> Processing Dependency: nginx-mod-http-perl = 1:1.12.2-1.el7 for package: 1:nginx-all-modules-1.12.2-1.el7.noarch
--> Processing Dependency: nginx-mod-http-xslt-filter = 1:1.12.2-1.el7 for package: 1:nginx-all-modules-1.12.2-1.el7.noarch
--> Processing Dependency: nginx-mod-mail = 1:1.12.2-1.el7 for package: 1:nginx-all-modules-1.12.2-1.el7.noarch
--> Processing Dependency: nginx-mod-stream = 1:1.12.2-1.el7 for package: 1:nginx-all-modules-1.12.2-1.el7.noarch
---> Package nginx-filesystem.noarch 1:1.12.2-1.el7 will be installed
---> Package openssl-libs.x86_64 1:1.0.1e-42.el7.9 will be updated
--> Processing Dependency: openssl-libs(x86-64) = 1:1.0.1e-42.el7.9 for package: 1:openssl-1.0.1e-42.el7.9.x86_64
---> Package openssl-libs.x86_64 1:1.0.2k-8.el7 will be an update
--> Running transaction check
---> Package libunwind.x86_64 2:1.2-2.el7 will be installed
---> Package nginx-mod-http-geoip.x86_64 1:1.12.2-1.el7 will be installed
--> Processing Dependency: GeoIP for package: 1:nginx-mod-http-geoip-1.12.2-1.el7.x86_64
--> Processing Dependency: libGeoIP.so.1()(64bit) for package: 1:nginx-mod-http-geoip-1.12.2-1.el7.x86_64
---> Package nginx-mod-http-image-filter.x86_64 1:1.12.2-1.el7 will be installed
--> Processing Dependency: gd for package: 1:nginx-mod-http-image-filter-1.12.2-1.el7.x86_64
--> Processing Dependency: libgd.so.2()(64bit) for package: 1:nginx-mod-http-image-filter-1.12.2-1.el7.x86_64
---> Package nginx-mod-http-perl.x86_64 1:1.12.2-1.el7 will be installed
---> Package nginx-mod-http-xslt-filter.x86_64 1:1.12.2-1.el7 will be installed
--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.11)(64bit) for package: 1:nginx-mod-http-xslt-filter-1.12.2-1.el7.x86_64
--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.18)(64bit) for package: 1:nginx-mod-http-xslt-filter-1.12.2-1.el7.x86_64
--> Processing Dependency: libexslt.so.0()(64bit) for package: 1:nginx-mod-http-xslt-filter-1.12.2-1.el7.x86_64
--> Processing Dependency: libxslt.so.1()(64bit) for package: 1:nginx-mod-http-xslt-filter-1.12.2-1.el7.x86_64
---> Package nginx-mod-mail.x86_64 1:1.12.2-1.el7 will be installed
---> Package nginx-mod-stream.x86_64 1:1.12.2-1.el7 will be installed
---> Package openssl.x86_64 1:1.0.1e-42.el7.9 will be updated
---> Package openssl.x86_64 1:1.0.2k-8.el7 will be an update
--> Running transaction check
---> Package GeoIP.x86_64 0:1.5.0-11.el7 will be installed
---> Package gd.x86_64 0:2.0.35-26.el7 will be installed
--> Processing Dependency: libpng15.so.15(PNG15_0)(64bit) for package: gd-2.0.35-26.el7.x86_64
--> Processing Dependency: libjpeg.so.62(LIBJPEG_6.2)(64bit) for package: gd-2.0.35-26.el7.x86_64
--> Processing Dependency: libpng15.so.15()(64bit) for package: gd-2.0.35-26.el7.x86_64
--> Processing Dependency: libjpeg.so.62()(64bit) for package: gd-2.0.35-26.el7.x86_64
--> Processing Dependency: libfontconfig.so.1()(64bit) for package: gd-2.0.35-26.el7.x86_64
--> Processing Dependency: libXpm.so.4()(64bit) for package: gd-2.0.35-26.el7.x86_64
--> Processing Dependency: libX11.so.6()(64bit) for package: gd-2.0.35-26.el7.x86_64
---> Package libxslt.x86_64 0:1.1.28-5.el7 will be installed
--> Running transaction check
---> Package fontconfig.x86_64 0:2.10.95-11.el7 will be installed
--> Processing Dependency: fontpackages-filesystem for package: fontconfig-2.10.95-11.el7.x86_64
--> Processing Dependency: font(:lang=en) for package: fontconfig-2.10.95-11.el7.x86_64
---> Package libX11.x86_64 0:1.6.5-1.el7 will be installed
--> Processing Dependency: libX11-common >= 1.6.5-1.el7 for package: libX11-1.6.5-1.el7.x86_64
--> Processing Dependency: libxcb.so.1()(64bit) for package: libX11-1.6.5-1.el7.x86_64
---> Package libXpm.x86_64 0:3.5.12-1.el7 will be installed
---> Package libjpeg-turbo.x86_64 0:1.2.90-5.el7 will be installed
---> Package libpng.x86_64 2:1.5.13-7.el7_2 will be installed
--> Running transaction check
---> Package fontpackages-filesystem.noarch 0:1.44-8.el7 will be installed
---> Package libX11-common.noarch 0:1.6.5-1.el7 will be installed
---> Package libxcb.x86_64 0:1.12-1.el7 will be installed
--> Processing Dependency: libXau.so.6()(64bit) for package: libxcb-1.12-1.el7.x86_64
---> Package lyx-fonts.noarch 0:2.2.3-1.el7 will be installed
--> Running transaction check
---> Package libXau.x86_64 0:1.0.8-2.1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================================================================================================================
 Package                                                              Arch                                            Version                                                   Repository                                     Size
====================================================================================================================================================================================================================================
Installing:
 nginx                                                                x86_64                                          1:1.12.2-1.el7                                            epel                                          529 k
Installing for dependencies:
 GeoIP                                                                x86_64                                          1.5.0-11.el7                                              base                                          1.1 M
 fontconfig                                                           x86_64                                          2.10.95-11.el7                                            base                                          229 k
 fontpackages-filesystem                                              noarch                                          1.44-8.el7                                                base                                          9.9 k
 gd                                                                   x86_64                                          2.0.35-26.el7                                             base                                          146 k
 gperftools-libs                                                      x86_64                                          2.4-8.el7                                                 base                                          272 k
 libX11                                                               x86_64                                          1.6.5-1.el7                                               base                                          606 k
 libX11-common                                                        noarch                                          1.6.5-1.el7                                               base                                          164 k
 libXau                                                               x86_64                                          1.0.8-2.1.el7                                             base                                           29 k
 libXpm                                                               x86_64                                          3.5.12-1.el7                                              base                                           55 k
 libjpeg-turbo                                                        x86_64                                          1.2.90-5.el7                                              base                                          134 k
 libpng                                                               x86_64                                          2:1.5.13-7.el7_2                                          base                                          213 k
 libunwind                                                            x86_64                                          2:1.2-2.el7                                               base                                           57 k
 libxcb                                                               x86_64                                          1.12-1.el7                                                base                                          211 k
 libxslt                                                              x86_64                                          1.1.28-5.el7                                              base                                          242 k
 lyx-fonts                                                            noarch                                          2.2.3-1.el7                                               epel                                          159 k
 nginx-all-modules                                                    noarch                                          1:1.12.2-1.el7                                            epel                                           16 k
 nginx-filesystem                                                     noarch                                          1:1.12.2-1.el7                                            epel                                           17 k
 nginx-mod-http-geoip                                                 x86_64                                          1:1.12.2-1.el7                                            epel                                           23 k
 nginx-mod-http-image-filter                                          x86_64                                          1:1.12.2-1.el7                                            epel                                           26 k
 nginx-mod-http-perl                                                  x86_64                                          1:1.12.2-1.el7                                            epel                                           35 k
 nginx-mod-http-xslt-filter                                           x86_64                                          1:1.12.2-1.el7                                            epel                                           25 k
 nginx-mod-mail                                                       x86_64                                          1:1.12.2-1.el7                                            epel                                           53 k
 nginx-mod-stream                                                     x86_64                                          1:1.12.2-1.el7                                            epel                                           76 k
Updating for dependencies:
 openssl                                                              x86_64                                          1:1.0.2k-8.el7                                            base                                          492 k
 openssl-libs                                                         x86_64                                          1:1.0.2k-8.el7                                            base                                          1.2 M

Transaction Summary
====================================================================================================================================================================================================================================
Install  1 Package  (+23 Dependent packages)
Upgrade             (  2 Dependent packages)

Total download size: 6.0 M
Background downloading packages, then exiting:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/26): fontpackages-filesystem-1.44-8.el7.noarch.rpm                                                                                                                                                        | 9.9 kB  00:00:00     
(2/26): fontconfig-2.10.95-11.el7.x86_64.rpm                                                                                                                                                                 | 229 kB  00:00:00     
(3/26): gd-2.0.35-26.el7.x86_64.rpm                                                                                                                                                                          | 146 kB  00:00:00     
(4/26): libX11-1.6.5-1.el7.x86_64.rpm                                                                                                                                                                        | 606 kB  00:00:00     
(5/26): libX11-common-1.6.5-1.el7.noarch.rpm                                                                                                                                                                 | 164 kB  00:00:00     
(6/26): libXau-1.0.8-2.1.el7.x86_64.rpm                                                                                                                                                                      |  29 kB  00:00:00     
(7/26): libXpm-3.5.12-1.el7.x86_64.rpm                                                                                                                                                                       |  55 kB  00:00:00     
(8/26): libjpeg-turbo-1.2.90-5.el7.x86_64.rpm                                                                                                                                                                | 134 kB  00:00:00     
(9/26): libpng-1.5.13-7.el7_2.x86_64.rpm                                                                                                                                                                     | 213 kB  00:00:00     
(10/26): libunwind-1.2-2.el7.x86_64.rpm                                                                                                                                                                      |  57 kB  00:00:00     
(11/26): libxcb-1.12-1.el7.x86_64.rpm                                                                                                                                                                        | 211 kB  00:00:00     
(12/26): libxslt-1.1.28-5.el7.x86_64.rpm                                                                                                                                                                     | 242 kB  00:00:00     
warning: /root/mypackages/lyx-fonts-2.2.3-1.el7.noarch.rpm.12470.tmp: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
Public key for lyx-fonts-2.2.3-1.el7.noarch.rpm.12470.tmp is not installed
(13/26): lyx-fonts-2.2.3-1.el7.noarch.rpm                                                                                                                                                                    | 159 kB  00:00:00     
(14/26): GeoIP-1.5.0-11.el7.x86_64.rpm                                                                                                                                                                       | 1.1 MB  00:00:01     
(15/26): nginx-filesystem-1.12.2-1.el7.noarch.rpm                                                                                                                                                            |  17 kB  00:00:00     
(16/26): nginx-mod-http-image-filter-1.12.2-1.el7.x86_64.rpm                                                                                                                                                 |  26 kB  00:00:00     
(17/26): nginx-all-modules-1.12.2-1.el7.noarch.rpm                                                                                                                                                           |  16 kB  00:00:00     
(18/26): nginx-mod-http-perl-1.12.2-1.el7.x86_64.rpm                                                                                                                                                         |  35 kB  00:00:00     
(19/26): nginx-mod-http-xslt-filter-1.12.2-1.el7.x86_64.rpm                                                                                                                                                  |  25 kB  00:00:00     
(20/26): nginx-mod-stream-1.12.2-1.el7.x86_64.rpm                                                                                                                                                            |  76 kB  00:00:00     
(21/26): nginx-mod-mail-1.12.2-1.el7.x86_64.rpm                                                                                                                                                              |  53 kB  00:00:00     
(22/26): nginx-1.12.2-1.el7.x86_64.rpm                                                                                                                                                                       | 529 kB  00:00:01     
(23/26): openssl-1.0.2k-8.el7.x86_64.rpm                                                                                                                                                                     | 492 kB  00:00:00     
(24/26): openssl-libs-1.0.2k-8.el7.x86_64.rpm                                                                                                                                                                | 1.2 MB  00:00:00     
(25/26): nginx-mod-http-geoip-1.12.2-1.el7.x86_64.rpm                                                                                                                                                        |  23 kB  00:00:01     
(26/26): gperftools-libs-2.4-8.el7.x86_64.rpm                                                                                                                                                                | 272 kB  00:00:13     
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                               438 kB/s | 6.0 MB  00:00:13     
exiting because "Download Only" specified

现在去你指定的目录位置下,你将会看到那里有下载好的软件包和依赖的软件。在我这种情况下,我已经把软件包下载到 /root/mypackages/ 目录下。 让我们来查看一下内容:

[root@node76 ~]# ls mypackages/
fontconfig-2.10.95-11.el7.x86_64.rpm           libpng-1.5.13-7.el7_2.x86_64.rpm      libXpm-3.5.12-1.el7.x86_64.rpm             nginx-mod-http-geoip-1.12.2-1.el7.x86_64.rpm         openssl-1.0.2k-8.el7.x86_64.rpm
fontpackages-filesystem-1.44-8.el7.noarch.rpm  libunwind-1.2-2.el7.x86_64.rpm        libxslt-1.1.28-5.el7.x86_64.rpm            nginx-mod-http-image-filter-1.12.2-1.el7.x86_64.rpm  openssl-libs-1.0.2k-8.el7.x86_64.rpm
gd-2.0.35-26.el7.x86_64.rpm                    libX11-1.6.5-1.el7.x86_64.rpm         lyx-fonts-2.2.3-1.el7.noarch.rpm           nginx-mod-http-perl-1.12.2-1.el7.x86_64.rpm
GeoIP-1.5.0-11.el7.x86_64.rpm                  libX11-common-1.6.5-1.el7.noarch.rpm  nginx-1.12.2-1.el7.x86_64.rpm              nginx-mod-http-xslt-filter-1.12.2-1.el7.x86_64.rpm
gperftools-libs-2.4-8.el7.x86_64.rpm           libXau-1.0.8-2.1.el7.x86_64.rpm       nginx-all-modules-1.12.2-1.el7.noarch.rpm  nginx-mod-mail-1.12.2-1.el7.x86_64.rpm
libjpeg-turbo-1.2.90-5.el7.x86_64.rpm          libxcb-1.12-1.el7.x86_64.rpm          nginx-filesystem-1.12.2-1.el7.noarch.rpm   nginx-mod-stream-1.12.2-1.el7.x86_64.rpm

正如你在上面输出所看到的, nginx软件包已经被依据所有依赖性下载完成了 。 请注意,这个插件适用于 yum install/yum update, 但是并不适用于 yum groupinstall。默认情况下,这个插件将会下载仓库中最新可用的软件包。然而你可以通过指定版本号来下载某个特定的软件版本。

例子:

yum install --downloadonly --downloaddir=/root/mypackages/ httpd-2.2.6-40.el7

此外,你也可以如下一次性下载多个包:

yum install --downloadonly --downloaddir=/root/mypackages/ httpd vsftpd

方法 2 使用 "Yumdownloader"工具来下载 RPM 软件包及其所有依赖包

“Yumdownloader” 是一款简单,但是却十分有用的命令行工具,它可以一次性下载任何 RPM 软件包及其所有依赖包。 以 root 身份运行如下命令安装 “Yumdownloader” 工具。

yum install yum-utils

一旦安装完成,运行如下命令去下载一个软件包,例如 httpd:

yumdownloader httpd

为了根据所有依赖性下载软件包,我们使用 --resolve 参数:

yumdownloader --resolve httpd

默认情况下,Yumdownloader 将会下载软件包到当前工作目录下。 为了将软件下载到一个特定的目录下,我们使用 --destdir 参数:

yumdownloader --resolve --destdir=/root/mypackages/ httpd

或者:

yumdownloader --resolve --destdir /root/mypackages/ httpd

终端输出:

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * epel: epel.mirror.angkasa.id
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-40.el7.centos.4 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-40.el7.centos.4 for package: httpd-2.4.6-40.el7.centos.4.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-40.el7.centos.4.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-40.el7.centos.4.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-40.el7.centos.4.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-40.el7.centos.4 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution
(1/5): apr-util-1.5.2-6.el7.x86_64.rpm | 92 kB 00:00:01 
(2/5): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00:02 
(3/5): apr-1.4.8-3.el7.x86_64.rpm | 103 kB 00:00:02 
(4/5): httpd-tools-2.4.6-40.el7.centos.4.x86_64.rpm | 83 kB 00:00:03 
(5/5): httpd-2.4.6-40.el7.centos.4.x86_64.rpm | 2.7 MB 00:00:19

让我们确认一下软件包是否被下载到我们指定的目录下:

ll /root/mypackages/
apr-1.4.8-3.el7.x86_64.rpm
apr-util-1.5.2-6.el7.x86_64.rpm
httpd-2.4.6-40.el7.centos.4.x86_64.rpm
httpd-tools-2.4.6-40.el7.centos.4.x86_64.rpm
mailcap-2.1.41-2.el7.noarch.rpm

不像 Downloadonly 插件,Yumdownload 可以下载一组相关的软件包。

yumdownloader "@Development Tools" --resolve --destdir /root/mypackages/

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏Java学习123

maven settings.xml 包含多个镜像库

2727
来自专栏大内老A

Oracle 系统表

Below is an alphabetical listing of the Oracle system tables that are commonly u...

1847
来自专栏Hadoop实操

Spark2Streaming读Kafka并写入到HBase

在前面的文章Fayson介绍了一些关于Spark2Streaming的示例如《Spark2Streaming读Kerberos环境的Kafka并写数据到HBas...

934
来自专栏运维

CentOS6.3 x86_64 mininstall 安装扫描之王nmap

CentOS6.3 x86_64 mininstall 安装扫描之王nmap 1,安装 [root@bogon ~]# yum -y install n...

582
来自专栏乐沙弥的世界

使用yum快速部署Oracle安装环境(11g)

    基于Linux安装过Oracle的童鞋们都应该清楚,安装Oracle的确是一件比较费时费力的差事,因为仅仅是前期的rpm包,内核参数,创建用户等等这些个...

1621
来自专栏ml

c/c++ 软件集成 安装和可卸载软件

  作为一个工程师应具备的一些能力: 1. 首先具备这款软件:     >inno  Setup      免费版还开源,良心货,妥妥的。 2. 这款软件上手也...

3467
来自专栏杨建荣的学习笔记

探索ASH 第一篇

老是在用ASH,对它的依赖感觉已经大于AWR,昨天心血来潮,想看看ash视图里面是怎么样的,过程也算曲折,不过也算抛砖引玉。 先看看v$active_sessi...

3758
来自专栏Ryan Miao

centos7查看系统版本,查看机器位数x86-64

前言 由于不经常使用linux,每当使用的时候就是安装软件,安装软件的时候就要选择安装包平台,是32位的还是64位的。这时候突然发现不知道怎么查,于是百度。虽然...

3105
来自专栏SnailTyan

Centos 7下Docker的安装与非root配置

1. CentOS 7下docker的安装 # 1. install yum-utils $ sudo yum install -y yum-utils Loa...

3126
来自专栏散尽浮华

openssl版本升级操作记录

需要部署nginx的https环境,之前是yum安装的openssl,版本比较低,如下: [root@nginx ~]# yum install -y pcre...

4649

扫码关注云+社区