如何在 CentOS 里下载 RPM 包及其所有依赖包

https://blog.csdn.net/linuxnews/article/details/53244315

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

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

  例子:
    yum install --downloadonly --downloaddir=/root/mypackages/ httpd

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

[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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

[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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值