当前位置: 代码迷 >> 综合 >> Cent OS 8更换yum源为阿里云镜像
  详细解决方案

Cent OS 8更换yum源为阿里云镜像

热度:35   发布时间:2023-12-16 20:56:54.0

命令 

[admin@bogon ~]$ mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
[admin@bogon ~]$ wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
--2020-12-01 16:29:01--  http://mirrors.aliyun.com/repo/Centos-8.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 27.221.24.204, 60.221.203.232, 119.167.197.116, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|27.221.24.204|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2595 (2.5K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”/etc/yum.repos.d/Ce 100%[===================>]   2.53K  --.-KB/s  用时 0s      2020-12-01 16:29:01 (304 MB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2595/2595])[admin@bogon ~]$ yum makecache
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
CentOS-8 - AppStream                            4.9 kB/s | 4.3 kB     00:00    
CentOS-8 - Base - mirrors.aliyun.com            3.5 MB/s | 2.2 MB     00:00    
CentOS-8 - Extras - mirrors.aliyun.com           39 kB/s | 8.6 kB     00:00    
元数据缓存已建立。
[admin@bogon ~]$ yum -y update
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
CentOS-8 - Base - mirrors.aliyun.com            4.8 MB/s | 2.2 MB     00:00    
CentOS-8 - Extras - mirrors.aliyun.com           30 kB/s | 8.6 kB     00:00    
......................省略N万字.......................................                
已安装:grub2-tools-efi-1:2.02-87.el8_2.x86_64                                        kernel-4.18.0-193.28.1.el8_2.x86_64                                           kernel-core-4.18.0-193.28.1.el8_2.x86_64                                      kernel-modules-4.18.0-193.28.1.el8_2.x86_64                                   完毕!
[admin@bogon ~]$ yum repolist
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
仓库标识                  仓库名称
AppStream                 CentOS-8 - AppStream
base                      CentOS-8 - Base - mirrors.aliyun.com
extras                    CentOS-8 - Extras - mirrors.aliyun.com
[admin@bogon ~]$ 

总结

如果权限不够会提示,例如:"mv: 无法将'/etc/yum.repos.d/CentOS-Base.repo' 移动至'/etc/yum.repos.d/CentOS-Base.repo.backup': 权限不够"

此时需要在出错命令之前加上"sudo"或者更换管理员账号登录重新执行

复制原配置

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

下载阿里云配置 

 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo

运行yum makecache生成缓存

 yum makecache

显示资源库的配置

 yum repolist

常用命令

yum常用命令
删除软件:yum remove AAA-x.x.x.rpm或者yum erase foo-x.x.x.rpm
升级软件:yum upgrade AAA或者yum update AAA
查询信息:yum info AAA
搜索软件(以包含foo字段为例):yum search AAA
显示软件包依赖关系:yum deplist AAA
 
   -q 静默执行 
   -t 忽略错误
  -R[分钟] 设置等待时间
  -y 自动应答yes
  --skip-broken 忽略依赖问题
  --nogpgcheck 忽略GPG验证
 
  check-update 检查可更新的包
  clean all    清除全部[缓存]
  clean packages 清除临时包文件(/var/cache/yum 下文件)
  clean headers  清除rpm头文件
  clean oldheaders 清除旧的rpm头文件
  deplist 列出包的依赖
  list 可安装和可更新的RPM包
  list installed 已安装的包
  list extras 已安装且不在资源库的包
  info 可安装和可更新的RPM包 信息
  info installed 已安装包的信息(-qa 参数相似)
  install[RPM包] 安装包
  localinstall 安装本地的 RPM包
  update[RPM包] 更新包
  upgrade 升级系统
  search[关键词] 搜索包
  provides[关键词] 搜索特定包文件名
  reinstall[RPM包] 重新安装包
  repolist 显示资源库的配置
  resolvedep 指定依赖
  remove[RPM包] 卸载包
       makecache  生成缓存