Linux服务器安装成功后,我们会经常使用yum安装rpm包以满足使用的需要。使用yum源安装rpm包有两种方式:
方式一:
搭建本地yum源环境,进行rpm包的安装,具体搭建方式,参考(chapter-5):
Linux常规基础配置_小黑要上天的博客-CSDN博客
方式二:
使用外部yum源环境,进行rpm包的安装。
安装完Linux服务器后,默认/etc/yum.repos.d/目录下已经有*.repo文件,只要Linux服务器可以联网,就可以使用它进行rpm包的安装。
另外,如果想要更新repo文件,可以使用阿里巴巴开源镜像站等网址。E.g:阿里巴巴开源镜像站。网址:centos镜像_centos下载地址_centos安装教程-阿里巴巴开源镜像站
1. 备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2. 下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
centos8(centos8官方源已下线,建议切换centos-vault源)
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
1.yum常用命令
1.1.yum list
yum list显示所有的程序包
1.2. yum repolist all
yum repolist all显示所有仓库
[root@centos79 yum.repos.d]# yum repolist all
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.bupt.edu.cn
* updates: mirrors.bupt.edu.cn
源标识 源名称 状态
C7.0.1406-base/x86_64 CentOS-7.0.1406 - Base 禁用
C7.0.1406-centosplus/x86_64 CentOS-7.0.1406 - CentOSPlus 禁用
C7.0.1406-extras/x86_64 CentOS-7.0.1406 - Extras 禁用
C7.0.1406-fasttrack/x86_64 CentOS-7.0.1406 - Fasttrack 禁用
C7.0.1406-updates/x86_64 CentOS-7.0.1406 - Updates 禁用
C7.1.1503-base/x86_64 CentOS-7.1.1503 - Base 禁用
C7.1.1503-centosplus/x86_64 CentOS-7.1.1503 - CentOSPlus 禁用
C7.1.1503-extras/x86_64 CentOS-7.1.1503 - Extras 禁用
C7.1.1503-fasttrack/x86_64 CentOS-7.1.1503 - Fasttrack 禁用
C7.1.1503-updates/x86_64 CentOS-7.1.1503 - Updates 禁用
C7.2.1511-base/x86_64 CentOS-7.2.1511 - Base 禁用
C7.2.1511-centosplus/x86_64 CentOS-7.2.1511 - CentOSPlus 禁用
C7.2.1511-extras/x86_64 CentOS-7.2.1511 - Extras 禁用
C7.2.1511-fasttrack/x86_64 CentOS-7.2.1511 - Fasttrack 禁用
C7.2.1511-updates/x86_64 CentOS-7.2.1511 - Updates 禁用
C7.3.1611-base/x86_64 CentOS-7.3.1611 - Base 禁用
C7.3.1611-centosplus/x86_64 CentOS-7.3.1611 - CentOSPlus 禁用
C7.3.1611-extras/x86_64 CentOS-7.3.1611 - Extras 禁用
C7.3.1611-fasttrack/x86_64 CentOS-7.3.1611 - Fasttrack 禁用
C7.3.1611-updates/x86_64 CentOS-7.3.1611 - Updates 禁用
C7.4.1708-base/x86_64 CentOS-7.4.1708 - Base 禁用
C7.4.1708-centosplus/x86_64 CentOS-7.4.1708 - CentOSPlus 禁用
C7.4.1708-extras/x86_64 CentOS-7.4.1708 - Extras 禁用
C7.4.1708-fasttrack/x86_64 CentOS-7.4.1708 - Fasttrack 禁用
C7.4.1708-updates/x86_64 CentOS-7.4.1708 - Updates 禁用
C7.5.1804-base/x86_64 CentOS-7.5.1804 - Base 禁用
C7.5.1804-centosplus/x86_64 CentOS-7.5.1804 - CentOSPlus 禁用
C7.5.1804-extras/x86_64 CentOS-7.5.1804 - Extras 禁用
C7.5.1804-fasttrack/x86_64 CentOS-7.5.1804 - Fasttrack 禁用
C7.5.1804-updates/x86_64 CentOS-7.5.1804 - Updates 禁用
C7.6.1810-base/x86_64 CentOS-7.6.1810 - Base 禁用
C7.6.1810-centosplus/x86_64 CentOS-7.6.1810 - CentOSPlus 禁用
C7.6.1810-extras/x86_64 CentOS-7.6.1810 - Extras 禁用
C7.6.1810-fasttrack/x86_64 CentOS-7.6.1810 - Fasttrack 禁用
C7.6.1810-updates/x86_64 CentOS-7.6.1810 - Updates 禁用
C7.7.1908-base/x86_64 CentOS-7.7.1908 - Base 禁用
C7.7.1908-centosplus/x86_64 CentOS-7.7.1908 - CentOSPlus 禁用
C7.7.1908-extras/x86_64 CentOS-7.7.1908 - Extras 禁用
C7.7.1908-fasttrack/x86_64 CentOS-7.7.1908 - Fasttrack 禁用
C7.7.1908-updates/x86_64 CentOS-7.7.1908 - Updates 禁用
C7.8.2003-base/x86_64 CentOS-7.8.2003 - Base 禁用
C7.8.2003-centosplus/x86_64 CentOS-7.8.2003 - CentOSPlus 禁用
C7.8.2003-extras/x86_64 CentOS-7.8.2003 - Extras 禁用
C7.8.2003-fasttrack/x86_64 CentOS-7.8.2003 - Fasttrack 禁用
C7.8.2003-updates/x86_64 CentOS-7.8.2003 - Updates 禁用
base/7/x86_64 CentOS-7 - Base 启用: 10,072
base-debuginfo/x86_64 CentOS-7 - Debuginfo 禁用
base-source/7 CentOS-7 - Base Sources 禁用
c7-media CentOS-7 - Media 禁用
centos-kernel/7/x86_64 CentOS LTS Kernels for x86_64 禁用
centos-kernel-experimental/7/x86_64 CentOS Experimental Kernels for x86_64 禁用
centosplus/7/x86_64 CentOS-7 - Plus 禁用
centosplus-source/7 CentOS-7 - Plus Sources 禁用
cr/7/x86_64 CentOS-7 - cr 禁用
docker-ce-nightly/7/x86_64 Docker CE Nightly - x86_64 禁用
docker-ce-nightly-debuginfo/7/x86_64 Docker CE Nightly - Debuginfo x86_64 禁用
docker-ce-nightly-source/7 Docker CE Nightly - Sources 禁用
docker-ce-stable/7/x86_64 Docker CE Stable - x86_64 启用: 245
docker-ce-stable-debuginfo/7/x86_64 Docker CE Stable - Debuginfo x86_64 禁用
docker-ce-stable-source/7 Docker CE Stable - Sources 禁用
docker-ce-test/7/x86_64 Docker CE Test - x86_64 禁用
docker-ce-test-debuginfo/7/x86_64 Docker CE Test - Debuginfo x86_64 禁用
docker-ce-test-source/7 Docker CE Test - Sources 禁用
extras/7/x86_64 CentOS-7 - Extras 启用: 515
extras-source/7 CentOS-7 - Extras Sources 禁用
fasttrack/7/x86_64 CentOS-7 - fasttrack 禁用
updates/7/x86_64 CentOS-7 - Updates 启用: 4,996
updates-source/7 CentOS-7 - Updates Sources 禁用
repolist: 15,828
[root@centos79 yum.repos.d]#
1.3.yum repolist enabled
yum repost enabled显示所有可用的仓库
[root@centos79 yum.repos.d]# yum repolist enabled
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.bupt.edu.cn
* updates: mirrors.bupt.edu.cn
源标识 源名称 状态
base/7/x86_64 CentOS-7 - Base 10,072
docker-ce-stable/7/x86_64 Docker CE Stable - x86_64 245
extras/7/x86_64 CentOS-7 - Extras 515
updates/7/x86_64 CentOS-7 - Updates 4,996
repolist: 15,828
[root@centos79 yum.repos.d]#
1.4.yum repolist disabled
yum repolist disabled显示所有禁用的仓库
[root@centos79 yum.repos.d]# yum repolist disabled
已加载插件:fastestmirror
源标识 源名称
C7.0.1406-base/x86_64 CentOS-7.0.1406 - Base
C7.0.1406-centosplus/x86_64 CentOS-7.0.1406 - CentOSPlus
C7.0.1406-extras/x86_64 CentOS-7.0.1406 - Extras
C7.0.1406-fasttrack/x86_64 CentOS-7.0.1406 - Fasttrack
C7.0.1406-updates/x86_64 CentOS-7.0.1406 - Updates
C7.1.1503-base/x86_64 CentOS-7.1.1503 - Base
C7.1.1503-centosplus/x86_64 CentOS-7.1.1503 - CentOSPlus
C7.1.1503-extras/x86_64 CentOS-7.1.1503 - Extras
1.5.yum search http
yum search http查看可用的http rpm包,http可以替换成其它可用的应用程序名
[root@centos79 yum.repos.d]# yum search http
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.bupt.edu.cn
* updates: mirrors.bupt.edu.cn
===================================================================== N/S matched: http =====================================================================
http-parser.i686 : HTTP request/response parser for C
http-parser.x86_64 : HTTP request/response parser for C
http-parser-devel.i686 : Development headers and libraries for http-parser
http-parser-devel.x86_64 : Development headers and libraries for http-parser
httpcomponents-client.noarch : HTTP agent implementation based on httpcomponents HttpCore
httpcomponents-client-javadoc.noarch : API documentation for httpcomponents-client
httpcomponents-core.noarch : Set of low level Java HTTP transport components for HTTP services
httpcomponents-core-javadoc.noarch : API documentation for httpcomponents-core
httpcomponents-project.noarch : Common POM file for HttpComponents
httpd.x86_64 : Apache HTTP Server
1.6.yum list available
yum list available显示可安装的程序包
[root@centos79 yum.repos.d]# yum list available |head -n 10
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.bupt.edu.cn
* updates: mirrors.bupt.edu.cn
可安装的软件包
389-ds-base.x86_64 1.3.11.1-1.el7_9 updates
389-ds-base-devel.x86_64 1.3.11.1-1.el7_9 updates
389-ds-base-libs.x86_64 1.3.11.1-1.el7_9 updates
389-ds-base-snmp.x86_64 1.3.11.1-1.el7_9 updates
由于管道被破坏而退出
[root@centos79 yum.repos.d]#
1.7.yum list updates
yum list updates显示可更新的程序包
[root@centos79 yum.repos.d]# yum list updates |head -n 10
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.bupt.edu.cn
* updates: mirrors.bupt.edu.cn
更新的软件包
apr-util.x86_64 1.5.2-6.el7_9.1 updates
cronie.x86_64 1.4.11-25.el7_9 updates
cronie-anacron.x86_64 1.4.11-25.el7_9 updates
docker-buildx-plugin.x86_64 0.10.5-1.el7 docker-ce-stable
[root@centos79 yum.repos.d]#
1.8.yum list installed
yum list installed显示已安装的程序包
[root@centos79 yum.repos.d]# yum list installed |head -n 10
已加载插件:fastestmirror
已安装的软件包
GConf2.x86_64 3.2.6-8.el7 @anaconda
GeoIP.x86_64 1.5.0-14.el7 @anaconda
LibRaw.x86_64 0.19.4-1.el7 @anaconda
ModemManager.x86_64 1.6.10-4.el7 @anaconda
ModemManager-glib.x86_64 1.6.10-4.el7 @anaconda
NetworkManager.x86_64 1:1.18.8-2.el7_9 @updates
NetworkManager-adsl.x86_64 1:1.18.8-2.el7_9 @updates
NetworkManager-glib.x86_64 1:1.18.8-2.el7_9 @updates
由于管道被破坏而退出
[root@centos79 yum.repos.d]#
1.9.yum list recent
yum list recent显示仓库中最近增加的程序包
[root@centos79 yum.repos.d]# yum list recent |head -n 10
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.bupt.edu.cn
* updates: mirrors.bupt.edu.cn
最近添加的软件包
bcel.noarch 5.2-19.el7_9 updates
bcel-javadoc.noarch 5.2-19.el7_9 updates
docker-buildx-plugin.x86_64 0.10.5-1.el7 docker-ce-stable
docker-ce.x86_64 3:24.0.2-1.el7 docker-ce-stable
[root@centos79 yum.repos.d]#
1.10.yum install -y RPM_Package
yum install -y RPM_Package安装RPM_Package包
[root@centos79 yum.repos.d]# yum install -y httpd
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.bupt.edu.cn
* updates: mirrors.bupt.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 httpd.x86_64.0.2.4.6-98.el7.centos.7 将被 升级
---> 软件包 httpd.x86_64.0.2.4.6-99.el7.centos.1 将被 更新
--> 正在处理依赖关系 httpd-tools = 2.4.6-99.el7.centos.1,它被软件包 httpd-2.4.6-99.el7.centos.1.x86_64 需要
--> 正在检查事务
---> 软件包 httpd-tools.x86_64.0.2.4.6-98.el7.centos.7 将被 升级
---> 软件包 httpd-tools.x86_64.0.2.4.6-99.el7.centos.1 将被 更新
--> 解决依赖关系完成依赖关系解决
=============================================================================================================================================================
Package 架构 版本 源 大小
=============================================================================================================================================================
正在更新:
httpd x86_64 2.4.6-99.el7.centos.1 updates 2.7 M
为依赖而更新:
httpd-tools x86_64 2.4.6-99.el7.centos.1 updates 94 k事务概要
=============================================================================================================================================================
升级 1 软件包 (+1 依赖软件包)总下载量:2.8 M
Downloading packages:
No Presto metadata available for updates
y
(1/2): httpd-tools-2.4.6-99.el7.centos.1.x86_64.rpm | 94 kB 00:00:15
(2/2): httpd-2.4.6-99.el7.centos.1.x86_64.rpm | 2.7 MB 00:00:23
-------------------------------------------------------------------------------------------------------------------------------------------------------------
总计 121 kB/s | 2.8 MB 00:00:23
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在更新 : httpd-tools-2.4.6-99.el7.centos.1.x86_64 1/4
正在更新 : httpd-2.4.6-99.el7.centos.1.x86_64 2/4
清理 : httpd-2.4.6-98.el7.centos.7.x86_64 3/4
清理 : httpd-tools-2.4.6-98.el7.centos.7.x86_64 4/4
验证中 : httpd-2.4.6-99.el7.centos.1.x86_64 1/4
验证中 : httpd-tools-2.4.6-99.el7.centos.1.x86_64 2/4
验证中 : httpd-tools-2.4.6-98.el7.centos.7.x86_64 3/4
验证中 : httpd-2.4.6-98.el7.centos.7.x86_64 4/4更新完毕:
httpd.x86_64 0:2.4.6-99.el7.centos.1作为依赖被升级:
httpd-tools.x86_64 0:2.4.6-99.el7.centos.1完毕!
1.11.yum update RPM_Package
yum update RPM_Package升级RPM_Package包
[root@centos79 yum.repos.d]# yum update httpd
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.bupt.edu.cn
* updates: mirrors.bupt.edu.cn
No packages marked for update
[root@centos79 yum.repos.d]#
1.12.yum info RPM_Package
yum info RPM_Package查看RPM_Package包信息
[root@centos79 yum.repos.d]# yum update http
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.bupt.edu.cn
* updates: mirrors.bupt.edu.cn
参数 http 没有匹配
没有可用软件包 http。
No packages marked for update
[root@centos79 yum.repos.d]# yum update httpd
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.bupt.edu.cn
* updates: mirrors.bupt.edu.cn
No packages marked for update
[root@centos79 yum.repos.d]# yum info httpd
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.bupt.edu.cn
* updates: mirrors.bupt.edu.cn
已安装的软件包
名称 :httpd
架构 :x86_64
版本 :2.4.6
发布 :99.el7.centos.1
大小 :9.4 M
源 :installed
来自源:updates
简介 : Apache HTTP Server
网址 :http://httpd.apache.org/
协议 : ASL 2.0
描述 : The Apache HTTP Server is a powerful, efficient, and extensible
: web server.[root@centos79 yum.repos.d]#
1.13.yum makecache [fast]
yum makecache [fast]构建本地缓存,用来提高搜索安装软件的速度,建议执行这个命令可以提升yum安装的速度。本地缓存存放路径:/var/cache/yum
[root@centos79 yum]# du -sm *
1 x86_64
[root@centos79 yum]# yum makecache fast
已加载插件:fastestmirror
Determining fastest mirrors
* base: mirrors.bfsu.edu.cn
* extras: mirrors.jlu.edu.cn
* updates: mirrors.jlu.edu.cn
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/6): extras/7/x86_64/primary_db | 249 kB 00:00:15
(2/6): base/7/x86_64/group_gz | 153 kB 00:00:22
(3/6): docker-ce-stable/7/x86_64/updateinfo | 55 B 00:00:23
(4/6): docker-ce-stable/7/x86_64/primary_db | 111 kB 00:00:23
(5/6): base/7/x86_64/primary_db | 6.1 MB 00:00:23
(6/6): updates/7/x86_64/primary_db | 21 MB 00:00:08
元数据缓存已建立
[root@centos79 yum]# du -sm *
178 x86_64
[root@centos79 yum]#
1.14.yum clean all
yum clean all清理本地缓存,本地缓存存放路径:/var/cache/yum
[root@centos79 yum]# du -sm *
178 x86_64
[root@centos79 yum]# yum clean all
已加载插件:fastestmirror
正在清理软件源: base docker-ce-stable extras updates
Cleaning up list of fastest mirrors
[root@centos79 yum]# du -sm *
1 x86_64
[root@centos79 yum]#
1.15.yum provides /path/command
yum provides /path/command查看某一文件来自于那个程序包
[root@centos79 yum]# yum provides /usr/bin/ls
已加载插件:fastestmirror
Determining fastest mirrors
* base: mirrors.bfsu.edu.cn
* extras: mirrors.bfsu.edu.cn
* updates: mirrors.bfsu.edu.cn
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/6): extras/7/x86_64/primary_db | 249 kB 00:00:15
(2/6): docker-ce-stable/7/x86_64/updateinfo | 55 B 00:00:22
(3/6): docker-ce-stable/7/x86_64/primary_db | 111 kB 00:00:22
(4/6): base/7/x86_64/primary_db | 6.1 MB 00:00:23
(5/6): updates/7/x86_64/primary_db | 21 MB 00:00:09
(6/6): base/7/x86_64/group_gz | 153 kB 00:00:32
coreutils-8.22-24.el7.x86_64 : A set of basic GNU tools commonly used in shell scripts
源 :base
匹配来源:
文件名 :/usr/bin/lscoreutils-8.22-24.el7_9.2.x86_64 : A set of basic GNU tools commonly used in shell scripts
源 :updates
匹配来源:
文件名 :/usr/bin/lscoreutils-8.22-24.el7_9.2.x86_64 : A set of basic GNU tools commonly used in shell scripts
源 :@updates
匹配来源:
文件名 :/usr/bin/ls[root@centos79 yum]#
另外yum还可以组的形式进行安装,相关命令如下,了解即可
命令 | 说明 |
yum groupinstall | 安装组包 |
yum groupupdate | 更新组包 |
yum grouplist | 列出组包 |
yum groupremove | 移除组包 |
yum groupinfo | 查看组包信息 |