centos上配置yum源

1. 进入yum源repo的目录

bash 复制代码
cd /etc/yum.repos.d/

然后可以通过ls查看下面所有的后缀为.repo的文件

2. 新建一个备份目录,将原有的.repo文件放到其中

bash 复制代码
mkdir yum.repos.d.backup
mv *.repo yum.repos.d.backup/

3. 获取阿里提供的repo配置文件

这里使用到了wget命令,如果系统中没有这个命令,可以看我的这篇文章,有具体的非常简单的安装方法,https://blog.csdn.net/qq_43699958/article/details/144395575

bash 复制代码
 wget -O /etc/yum.repos.d/CentOS7.aliyun.repo http://mirrors.aliyun.com/repo/Centos-7.repo

用ll命令查看下文件

bash 复制代码
[root@localhost yum.repos.d]# ll
总用量 4
-rw-r--r--. 1 root root 2523 8月   4 2022 CentOS7.aliyun.repo
drwxr-xr-x. 2 root root  220 12月 11 10:23 yum.repos.d.backup

这个文件的具体内容如下,也可以新建个CentOS7.aliyun.repo文件,将文件内容通过vi工具写进去

bash 复制代码
# 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-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

4. 清理以前的yum配置,并进行yum的缓存建立和软件更新,以此执行如下命令

bash 复制代码
yum clean all
bash 复制代码
yum makecache
bash 复制代码
yum update

5. 检验是否安装成功

安装个软件试试

bash 复制代码
[root@localhost yum.repos.d]# yum install net-tools
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                                                                            | 3.6 kB  00:00:00
extras                                                                                                                                                                          | 2.9 kB  00:00:00
updates                                                                                                                                                                         | 2.9 kB  00:00:00
正在解决依赖关系
--> 正在检查事务
---> 软件包 net-tools.x86_64.0.2.0-0.25.20131004git.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

=======================================================================================================================================================================================================
 Package                                       架构                                       版本                                                          源                                        大小
=======================================================================================================================================================================================================
正在安装:
 net-tools                                     x86_64                                     2.0-0.25.20131004git.el7                                      base                                     306 k

事务概要
=======================================================================================================================================================================================================
安装  1 软件包

总下载量:306 k
安装大小:917 k
Is this ok [y/d/N]:

安装完成后执行ifconfig命名,是可以查看本机ip的,说明安装成功~

奥利给~

相关推荐
chian-ocean19 分钟前
Linux 文件缓冲区:高效数据访问的幕后推手
linux·运维·服务器
加油=^_^=21 分钟前
【Linux】进程优先级 | 进程调度(三)
linux·运维·服务器
吃汤圆的抹香鲸1 小时前
GoLand 安装包 绿色版 Win,Mac,Linux 包含IntelliJ全家桶 专为Go语言设计的集成开发环境(IDE)
linux·windows·macos·go·intellij-idea·go1.19
追寻光1 小时前
Cannot find a valid baseurl for repo: base/7/x86_64
linux
元气满满的热码式1 小时前
Docker数据卷操作实战
linux·运维·docker·云原生·容器
陆沙1 小时前
deepseek-r1-centos-本地服务器配置方法
linux·服务器·centos
北京耐用通信1 小时前
航空装配自动化神器Ethercat转profient网关搭配机器人精准控制
运维·机器人·自动化
吃汤圆的抹香鲸1 小时前
Rider 安装包 绿色版 Win/Mac/Linux 适合.NET和游戏开发者使用 2025全栈开发终极指南:从零配置到企业级实战
linux·运维·windows·sql·游戏·macos·.net
sz66cm2 小时前
Linux基础 -- ARM 32 位架构动态注入代码技术文档
linux·arm开发·架构
Mr.pyZhang4 小时前
Android构建系统 - 04 编译产物
android·linux