CentOS 利用Yum 下載軟件包

需求:
假如需要下載某些rpm軟件包,但這些rpm軟件包已經(jīng)很難找到下載資源并且很多是存在依賴包,一個(gè)一個(gè)下載很麻煩,但很多網(wǎng)絡(luò)yum源提是可以直接在線安裝,如果用戶需要是把rpm軟件包和依賴包一并下載,這時(shí),使用網(wǎng)絡(luò)yum源下載rpm軟件包最為方便。

Yum下載軟件包有兩種方法:(本教程以阿里云Yum源為下載RPM軟件包)

Linux System Environment

[root@yumserver ~]cat /etc/redhat-release                   #==》系統(tǒng)版本
CentOS Linux release 7.5.1804 (Core)
[root@yumserver ~]uname –r                                 #==》內(nèi)核版本
3.10.0-862.el7.x86_64
[root@yumserver ~] uname -m                                 #==》系統(tǒng)架構(gòu)
x86_64
[root@yumserver ~]echo $LANG                               #==》系統(tǒng)字符集
en_US.UTF-8

方法一、使用yum源的downloadonly插件(Yum工具自帶此插件)
提示:此方法會(huì)把RPM軟件包和相關(guān)的依賴包一并下載,但本地系統(tǒng)不會(huì)安裝下載的軟件,推薦使用此方法。

1、配置阿里云Yum源

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache

2、使用yum源命令下載createrepo軟件包并指定路徑

[root@yumserver ~]# mkdir -p /tmp/yum
[root@yumserver ~]# yum -y install createrepo --downloadonly --downloaddir=/tmp/yum
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package createrepo.noarch 0:0.9.9-28.el7 will be installed
--> Processing Dependency: python-deltarpm for package: createrepo-0.9.9-28.el7.noarch
--> Processing Dependency: deltarpm for package: createrepo-0.9.9-28.el7.noarch
--> Running transaction check
---> Package deltarpm.x86_64 0:3.6-3.el7 will be installed
---> Package python-deltarpm.x86_64 0:3.6-3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================
 Package                     Arch               Version                     Repository        Size
===================================================================================================
Installing:
 createrepo                  noarch             0.9.9-28.el7                base              94 k
Installing for dependencies:
 deltarpm                    x86_64             3.6-3.el7                   base              82 k
 python-deltarpm             x86_64             3.6-3.el7                   base              31 k

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

Total download size: 207 k
Installed size: 558 k
Background downloading packages, then exiting:
(1/3): createrepo-0.9.9-28.el7.noarch.rpm                                   |  94 kB  00:00:00     
(2/3): deltarpm-3.6-3.el7.x86_64.rpm                                        |  82 kB  00:00:00     
(3/3): python-deltarpm-3.6-3.el7.x86_64.rpm                                 |  31 kB  00:00:00     
---------------------------------------------------------------------------------------------------
Total                                                              1.8 MB/s | 207 kB  00:00:00     
exiting because "Download Only" specified
[root@yumserver ~]# ls -lrth /tmp/yum
total 212K
-rw-r--r-- 1 root root 83K Jul  4  2014 deltarpm-3.6-3.el7.x86_64.rpm
-rw-r--r-- 1 root root 32K Jul  4  2014 python-deltarpm-3.6-3.el7.x86_64.rpm
-rw-r--r-- 1 root root 94K Aug 10  2017 createrepo-0.9.9-28.el7.noarch.rpm

方法二:利用Yum工具緩存功能
提示:此方法會(huì)把RPM軟件包和相關(guān)的依賴包一并下載,并且本地系統(tǒng)會(huì)把下載的軟件包一并安裝。

1、配置阿里云Yum源

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache

2、/etc/yum.conf配置文件參數(shù)說明

[root@yumserver ~]# cat /etc/yum.conf 
[main]
cachedir=/var/cache/yum/$basearch/$releasever  ##指定yum緩存的RPM軟件包
keepcache=0                                ##1保存已安裝的RPM軟件包,0不保存
debuglevel=2                               ##調(diào)試級(jí)別(0-10)
logfile=/var/log/yum.log                      ##記錄yum下載的軟件包記錄
exactarch=1 
obsoletes=1
gpgcheck=1                                ##是否密鑰檢查
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release

3、修改/etc/yum.conf配置文件將keepcache=0改成keepcache=1,保存退出

[root@yumserver ~]# sed -i 's/keepcache=0/keepcache=1/g' /etc/yum.conf
[root@yumserver ~]# cat /etc/yum.conf | grep keepcache
keepcache=1
[root@yumserver ~]# systemctl daemon-reload
[root@yumserver ~]# yum makecache
[root@yumserver ~]# rpm -qa | grep createrepo
[root@yumserver ~]# yum -y install createrepo
[root@yumserver ~]# ls -lrth /var/cache/yum/x86_64/7/base/packages/
total 212K
-rw-r--r-- 1 root root 83K Jul  4  2014 deltarpm-3.6-3.el7.x86_64.rpm
-rw-r--r-- 1 root root 32K Jul  4  2014 python-deltarpm-3.6-3.el7.x86_64.rpm
-rw-r--r-- 1 root root 94K Aug 10  2017 createrepo-0.9.9-28.el7.noarch.rp
[root@yumserver ~]# rpm -qa | grep createrepo
createrepo-0.9.9-28.el7.noarch
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容