Yum
全称为 Yellow dog Updater Modified,是RedHat以及CentOS中的基于RPM软件包管理器。它可以自动处理依赖性关系,无须繁琐地一次次下载、安装。
简单使用
- 列出所有可安裝的软件清单
yum list
# 列出名为 perl 的包
yum list perl
# 列出 perl 开头的包
yum list perl*
# 列出资源库中所有可以更新的rpm包
yum list updates
# 列出已经安装的所有的rpm包
yum list installed
# 和 grep 配合
# 软件名 版本号 信息
# 信息中,带@:已安装,base:linux自带软件包
yum list | grep ***
- 列举资源信息
yum info
# 用法同 yum list
- 安装软件
# -y: 安装中的交互问答默认选y
yum install -y wget
配置yum源
yum仓库就是使用yum命令下载软件的镜像地址。众所周知,从国外下载软件速度非常慢,很多情况下都无法下载。
下面提供了阿里和清华大学两个镜像仓库配置操作说明。
阿里镜像配置
进入 阿里镜像网址
点击 centos
,进行配置说明页面,选择对应的系统版本,根据步骤操作即可
- 备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
- 下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
# CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo
# or
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo
- 清除缓存
# 清除系统所有的yum缓存
yum clean all
# 生成yum缓存
yum makecache
可能碰到的问题
更改阿里源报错
[root@CentOS yum.repos.d]# yum makecacheLoaded plugins: fastestmirror
Determining fastest mirrors
http://mirrors.aliyun.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
Trying other mirror.
To address this issue please refer to the below knowledge base article
https://access.redhat.com/articles/1320623
If above article doesn't help to resolve this issue please open a ticket with Red Hat Support.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again
查阅资料,是停止维护了
CentoS 6 停止维护更新日期2020年11月30日
CentOS 7 停止维护更新日期2024年6月30日
CentOS 8 停止维护更新日期2021年12月31日
可以使用阿里云的另一个源(centos-vault),直接用下面内容替换文件
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-6.4 - Base
baseurl=http://mirrors.aliyun.com/centos-vault/6.4/os/x86_64/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
[updates]
name=CentOS-6.4 - Updates
baseurl=http://mirrors.aliyun.com/centos-vault/6.4/updates/x86_64/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
[extras]
name=CentOS-6.4 - Extras
baseurl=http://mirrors.aliyun.com/centos-vault/6.4/extras/x86_64/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
[centosplus]
name=CentOS-6.4 - Plus
baseurl=http://mirrors.aliyun.com/centos-vault/6.4/centosplus/x86_64/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
[contrib]
name=CentOS-6.4 - Contrib
baseurl=http://mirrors.aliyun.com/centos-vault/6.4/contrib/x86_64/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
虚拟机CentOS 6.5,使用yum报错
[root@CentOS tmp]# yum list
Loaded plugins: fastestmirror
Determining fastest mirrors
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
Eg. Invalid release/repo/arch combination/
removing mirrorlist with no valid mirrors: /var/cache/yum/x86_64/6/base/mirrorlist.txt
Error: Cannot find a valid baseurl for repo: base
从报错可以看出是yum
的源有问题,进入配置文件 /etc/yum.repos.d/CentOS-Base.repo,找到 mirrorlist
的url,点击发现已经Invalid
,根据上文阿里镜像配置,改为阿里源