方法一、利用 Downloadonly 插件下载 RPM 软件包及其所有依赖包
默认情况下,这个命令将会下载并把软件包保存到 /var/cache/yum/ 的 rhel-{arch}-channel/packageslocation 目录,不过,你也可以下载和保存软件包到任何位置,你可以通过 –downloaddir 选项来指定。
yum install --downloadonly --downloaddir=<directory> <package-name>
例子:
yum install --downloadonly --downloaddir=/root/mypackages/ httpd
[root@xuegod70 ~]# yum install --downloadonly --downloaddir=/root/mypackages/ httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.ustc.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-80.el7.centos.1 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-80.el7.centos.1 for package: httpd-2.4.6-80.el7.centos.1.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-80.el7.centos.1.x86_64
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.4.6-80.el7.centos.1 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved =====================================================================================================================
Package Arch Version Repository Size
=====================================================================================================================
Installing:
httpd x86_64 2.4.6-80.el7.centos.1 updates 2.7 M
Installing for dependencies:
httpd-tools x86_64 2.4.6-80.el7.centos.1 updates 90 k
mailcap noarch 2.1.41-2.el7 Cent7 31 k Transaction Summary
=====================================================================================================================
Install 1 Package (+2 Dependent packages) Total download size: 2.8 M
Installed size: 9.6 M
Background downloading packages, then exiting:
(1/2): httpd-tools-2.4.6-80.el7.centos.1.x86_64.rpm | 90 kB 00:00:00
(2/2): httpd-2.4.6-80.el7.centos.1.x86_64.rpm | 2.7 MB 00:00:00
---------------------------------------------------------------------------------------------------------------------
Total 4.1 MB/s | 2.8 MB 00:00:00
exiting because "Download Only" specified
方法二、使用 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
[root@xuegod70 ~]# yumdownloader --resolve --destdir=/root/mypackages/ httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.ustc.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-80.el7.centos.1 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-80.el7.centos.1 for package: httpd-2.4.6-80.el7.centos.1.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-80.el7.centos.1.x86_64
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.4.6-80.el7.centos.1 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution
(1/3): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00:00
(2/3): httpd-tools-2.4.6-80.el7.centos.1.x86_64.rpm | 90 kB 00:00:00
(3/3): httpd-2.4.6-80.el7.centos.1.x86_64.rpm | 2.7 MB 00:00:00
详细参考如下:
https://blog.csdn.net/linuxnews/article/details/53244315