• centos8 yum install failed to set locale, defaulting to C


    一.问题来源

    新创建一个镜像,基础环境是centos8,启动镜像后执行yum install make出现了下边的问题

    Failed to set locale, defaulting to C.UTF-8
    CentOS-8 - AppStream                                                                61  B/s |  38  B     00:00    
    Error: Failed to download metadata for repo 'AppStream': Cannot prepare internal mirrorlist: No URLs in mirrorlist

    根据这个问题开始各种百度,百度的解决方案有

    echo "export LC_ALL=en_US.UTF-8"  >>  /etc/profile
    source /etc/profile
    或是

    echo "export LC_ALL=en_US.UTF-8"  >>  ~/.bashrc
    source ~/.bashrc
    或是

    more  /etc/sysconfig/i18n 
    vi  /etc/sysconfig/i18n
    source   /etc/sysconfig/i18n

    或是

    dnf install langpacks-en glibc-all-langpacks -y
    localectl set-locale LANG=en_US.UTF-8
    等等,然而并没有解决我的问题而是又引出了一系列的问题!!!!!!

    二.分析问题

    1.首先最开始出现问题就是我们的yum镜像源的问题,那么yum就是不能使用的,你要确认这一点,就不要再想着使用yum下载什么语言去解决这个问题了,先要把yum的镜像源解决下

    Failed to set locale, defaulting to C.UTF-8
    CentOS-8 - AppStream                                                                                61  B/s |  38  B     00:00    
    Error: Failed to download metadata for repo 'AppStream': Cannot prepare internal mirrorlist: No URLs in mirrorlist

    2.关于这个locale报出来的问题你可以先自己验证下是否有相应的语言,没有就别费劲了

    locale -a    #下边就是最开始查询的结果,很明显没有我们想要的 en_US.UTF-8

    locale: Cannot set LC_CTYPE to default locale: No such file or directory
    locale: Cannot set LC_MESSAGES to default locale: No such file or directory
    locale: Cannot set LC_COLLATE to default locale: No such file or directory
    C
    C.utf8
    POSIX

     三.解决方式

    1.解决镜像源的问题,(cp别人的,当然要注明人家的地址了,这么有素质的人)

    CentOS 8: yum设置为源 - 腾讯云开发者社区-腾讯云 (tencent.com)

    1、将源文件备份

    cd /etc/yum.repos.d/ && mkdir backup && mv *repo backup/

    2、下载源文件

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

    3、更新源里面的地址

    1. sed -i -e "s|mirrors.cloud.aliyuncs.com|mirrors.aliyun.com|g " /etc/yum.repos.d/CentOS-*
    2. sed -i -e "s|releasever|releasever-stream|g" /etc/yum.repos.d/CentOS-*

    4、生成缓存

    yum clean all && yum makecache

    2.解决locale问题

    在你进行完第一个操作之后查询locale -a 你会发现你已经拥有了很多国家的语言编码,你要明确的知道要的是en_US开头的utf8,我的是en_US.utf8注意大小写)这个时候你就可以使用你百度到的各种让它生效的方式了,前提是你要能查到,查不到你让它生效什么呢

     echo "export LC_ALL=en_US.utf8"  >>  /etc/profile

    source /etc/profile

    你百度到的让她生效的方式应该是都可以奏效了

    3.有的人会发现你这不行啊,我这执行完还是报这么一坨

    bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
    bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
    bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF8)
    bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF8)
    bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
    bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
    bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
    bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)

    查下你的文件,你在翻到这篇文章之前在这个文件里边设置了多少次,看下写的对不对,不对的编辑你的文件删除掉之后再让他生效才能找到正确的语言编码(我的是en_US.utf8)返回3-2查询

     4.yum install 成功   撒花

     

  • 相关阅读:
    python基础内容
    git的使用规范及技巧总结
    Redis(六) 主从模式
    微服务架构学习与思考(14):监控和可观测性详细介绍
    【hacker送书第2期】计算机考研精炼1000题
    洛谷P3694
    深眸科技迭代深度学习算法,以AI机器视觉技术扩围工业应用场景
    Freeswitch中CHANNEL_HANGUP外呼挂断事件
    git协同操作
    c++11的类型推导auto使用
  • 原文地址:https://blog.csdn.net/weixin_39523456/article/details/127683911