方法一、利用 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