centos yum命令安装并保存rpm安装包

一、修改yum.conf配置文件参数,打开安装包缓存字段keepcache=1

[root@localhost yum.repos.d]# vim /etc/yum.conf 
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1

二、执行yum 安装命令

[root@localhost yum.repos.d]# yum install telnet -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * centos-sclo-rh: mirrors.bupt.edu.cn
 * centos-sclo-sclo: mirrors.bupt.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package telnet.x86_64 1:0.17-66.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================
 Package                    Arch                       Version                            Repository                   Size
============================================================================================================================
Installing:
 telnet                     x86_64                     1:0.17-66.el7                      updates                      64 k

Transaction Summary
============================================================================================================================
Install  1 Package

Total download size: 64 k
Installed size: 113 k
Downloading packages:
telnet-0.17-66.el7.x86_64.rpm                                                                        |  64 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:telnet-0.17-66.el7.x86_64                                                                              1/1 
  Verifying  : 1:telnet-0.17-66.el7.x86_64                                                                              1/1 

Installed:
  telnet.x86_64 1:0.17-66.el7                                                                                               

Complete!
[root@localhost yum.repos.d]# 

三、查看缓存的rpm安装包

[root@localhost /]# cd /var/cache/yum/x86_64/7/updates/packages/
[root@localhost packages]# ll
total 68
-rw-r--r-- 1 root root 65932 Nov 18  2020 telnet-0.17-66.el7.x86_64.rpm
[root@localhost packages]# 

 如果updates目录下没有就去base目录下的packages下找。

原文地址:https://www.cnblogs.com/sky-cheng/p/15466488.html