提示错误:![](https://i-blog.csdnimg.cn/direct/63435e33527545c6b31b49358c024ba2.png)
解决方案:
第一步 排除网络问题:
ping baidu.com
成功如下:
第二步 排除DNS配置问题:
nslookup google.com
成功如下:
第三步 查看mirrorlist.txt是否存在:
发现丢失,本人路径在这:/var/cache/yum/x86_64/7,这个路径下有三个文件夹,如下图:
发现每个文件下的mirrorlist.txt不存在,在每个文件夹下创建新的mirrorlist.txt。
本人创建文件用的vim,cd到当前路径,直接运行命令 vim mirrorlist.txt即可,直接生成新的文件,把如下代码写入保存:
# CentOS-Base.repo
#
# This file is part of the CentOS Software Repositories.
#
# CentOS-Base.repo is the configuration file for all of the default
# repositories in the CentOS software distribution.
#
# 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
baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
创建生成 mirrorlist.txt之后,运行如下代码:
echo "http://vault.centos.org/7.6.1810/os/x86_64/" > /var/cache/yum/x86_64/7/base/mirrorlist.txt
echo "http://vault.centos.org/7.6.1810/extras/x86_64/" > /var/cache/yum/x86_64/7/extras/mirrorlist.txt
echo "http://vault.centos.org/7.6.1810/updates/x86_64/" > /var/cache/yum/x86_64/7/updates/mirrorlist.txt
注意!!!记得修改代码中的 7.6.1810 为自己的Centos版本号,查看版本号可以用如下代码:
cat /etc/redhat-release
运行完下图所示:
再次运行yum安装命令成功:
最后附yum安装中文包指南:
yum install -y kde-l10n-Chinese #安装命令
localedef -c -f UTF-8 -i zh_CN zh_CN.utf8 #配置
locale -a #查看是否配置成功
locake -a运行结果:
另外:如果用上面代码配置不成功的话,可以进入root目录下修改.bashrc文件:
vim .bashrc
#在该文件中加入以下代码即可
export LANG=zh_CN.utf8
export LC_ALL=zh_CN.utf8
用 locale 命令查看是否成功,成功如下: