centos7下执行yum命令报错

 

前言

 
在Linux系统中,安装nginx时候,需要先安装环境。
Nginx是使用C语言开发,安装nginx需要先从官网上将源码下载,然后编译,编译需要gcc环境,但是在安装gcc环境的时候,执行命令报错。

yum install –y gcc-c++

 
 

一、报错信息:

 

报错信息一:

[root@localhost ~]# yum install –y gcc-c++
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile

  • base: mirrors.aliyun.com * c7-media: * extras:
    mirrors.aliyun.com * updates: mirrors.aliyun.com
    http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml:
    [Errno 14] curl#7 - “Failed connect to mirrors.aliyuncs.com:80; 拒绝连接”
    正在尝试其它镜像。
    http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml:
    [Errno 14] curl#6 - “Could not resolve host:
    mirrors.cloud.aliyuncs.com; 未知的错误” 正在尝试其它镜像。 base
    | 3.6 kB 00:00:00 file:///media/CentOS/repodata/repomd.xml:
    [Errno 14] curl#37 - “Couldn’t open file
    /media/CentOS/repodata/repomd.xml” 正在尝试其它镜像。
    file:///media/cdrecorder/repodata/repomd.xml: [Errno 14] curl#37 -
    “Couldn’t open file /media/cdrecorder/repodata/repomd.xml” 正在尝试其它镜像。
    file:///media/cdrom/repodata/repomd.xml: [Errno 14] curl#37 -
    “Couldn’t open file /media/cdrom/repodata/repomd.xml” 正在尝试其它镜像。

One of the configured repositories failed (CentOS-7 - Media), and
yum doesn’t have enough cached data to continue. At this point the
only safe thing yum can do is fail. There are a few ways to work
“fix” this:

 1. Contact the upstream for the repository and get them to fix the problem.

 2. Reconfigure the baseurl/etc. for the repository, to point to a working
    upstream. This is most often useful if you are using a newer
    distribution release than is supported by the repository (and the
    packages for the previous distribution release still work).

 3. Run the command with the repository temporarily disabled
        yum --disablerepo=c7-media ...

 4. Disable the repository permanently, so yum won't use it by default. Yum
    will then just ignore the repository until you permanently enable it
    again or use --enablerepo for temporary usage:

        yum-config-manager --disable c7-media
    or
        subscription-manager repos --disable=c7-media

 5. Configure the failing repository to be skipped, if it is unavailable.
    Note that yum will try to contact the repo. when it runs most commands,
    so will have to try and fail each time (and thus. yum will be be much
    slower). If it is a very temporary problem though, this is often a nice
    compromise:

        yum-config-manager --save --setopt=c7-media.skip_if_unavailable=true

failure: repodata/repomd.xml from c7-media: [Errno 256] No more
mirrors to try. file:///media/CentOS/repodata/repomd.xml: [Errno 14]
curl#37 - “Couldn’t open file /media/CentOS/repodata/repomd.xml”
file:///media/cdrecorder/repodata/repomd.xml: [Errno 14] curl#37 -
“Couldn’t open file /media/cdrecorder/repodata/repomd.xml”
file:///media/cdrom/repodata/repomd.xml: [Errno 14] curl#37 -
“Couldn’t open file /media/cdrom/repodata/repomd.xml”

 
 

报错信息二:centos7 yum安装使用时提示 cannot find a valid baseurl for repo:base/7/x86_64 。

 
 

二、解决方案

 

第一步:先看本地yum是否安装

直接linux下输入yum查看:出现如图信息说明已经安装,就不需要再安装,直接到第四步。

[root@localhost yum.repos.d]# yum

centos7下执行yum命令报错_第1张图片
 
 

第二步:卸载yum:如果上一步没有安装,则安装

rpm -qa | grep yum | xargs rpm -e --nodeps

 

第三步:安装yum:

 
 

第四步:yum命令报错解决方案

这个报错是因为yum配置源不对的问题,这个配置文件在/etc/yum.repos.d/ 目录下的CentOS-Base.repo文件中,重新下载一个阿里或者163的yum源配置文件,文件名字不一样的改成CentOS-Base.repo。

下载163yum镜像源(根据自己的版本选择不同的下载地址):
 
 
第1步: 备份你的原镜像文件,以免出错后可以恢复。

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

 
第2步: 下载新的CentOS-Base.repo

CentOS 6下载命令:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo

CentOS 7下载命令:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo

 
3、 第3步: 运行 yum clean all,yum makecache 生成缓存

yum clean all
yum makecache

 
 
3、 **第4步:**如果还不行,那么就需要换一个下载源地址。

第五步:可以执行命令了:

yum install –y gcc-c++

你可能感兴趣的:(linux,java)