CentOS 8 执行yum命令报错:Failed to set locale, defaulting to C.UTF-8

今天Docker新搞了一个CentOS镜像,在运行基于该镜像的容器,执行yum命令时,遇到了如下报错:

bash 复制代码
[root@GC Administrator]# yum install -y yum-utils
Failed to set locale, defaulting to C.UTF-8
CentOS Linux 8 - AppStream                                                               41  B/s |  38  B     00:00
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist

目前使用 docker pull centos 不指定tag,拉取的latest,centos的版本为 8.4.2105

bash 复制代码
[root@GC Administrator]# cat /etc/redhat-release 
CentOS Linux release 8.4.2105

1. yum镜像源问题

其中 Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist 是yum镜像源的问题,这个问题我在之前的一篇文章中已经总结过解决方案。
CentOS 执行yum命令报错【错误:为仓库 'appstream' 下载元数据失败: ...】

你可以参考上述文章进行解决,你也可以直接运行下面的命令进行解决(上述文章中提到的其中一种方案)

bash 复制代码
# Centos 8 之前版本
# 以 CentOS 7.9.2009 为例
minorver=7.9.2009
sudo sed -e "s|^mirrorlist=|#mirrorlist=|g" \
         -e "s|^#baseurl=http://mirror.centos.org/centos/\$releasever|baseurl=https://mirrors.aliyun.com/centos-vault/$minorver|g" \
         -i.bak \
         /etc/yum.repos.d/CentOS-*.repo

# CentOS 8 版本
# 以 CentOS 8.5.2111 为例
minorver=8.5.2111
sudo sed -e "s|^mirrorlist=|#mirrorlist=|g" \
         -e "s|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever|baseurl=https://mirrors.aliyun.com/centos-vault/$minorver|g" \
         -i.bak \
         /etc/yum.repos.d/CentOS-*.repo

2. 语言环境问题

其中Failed to set locale, defaulting to C.UTF-8是系统语言环境问题

下面是解决方案:

1)查看本地安装的语言包

bash 复制代码
[root@GC ~]# locale -a
C
C.utf8
POSIX

2)安装语言包

安装中文语言包:yum install glibc-langpack-zh

安装英文语言包:yum install glibc-langpack-en

我这里只安装了 中文语言包 👇

bash 复制代码
[root@GC Administrator]# locale -a
C
C.utf8
POSIX
zh_CN
zh_CN.gb18030
zh_CN.gbk
zh_CN.utf8
zh_HK
zh_HK.utf8
zh_SG
zh_SG.gbk
zh_SG.utf8
zh_TW
zh_TW.euctw
zh_TW.utf8

3)设置语言环境

bash 复制代码
echo "export LC_ALL=zh_CN.utf8" >> /etc/profile
source /etc/profile

从你已安装的语言中,选择你想要设置的语言,我这里选择的是zh_CN.utf8

4)验证语言是否设置成功

bash 复制代码
[root@GC Administrator]# yum install -y yum-utils
Last metadata expiration check: 0:17:50 ago on 2023年08月25日 星期五 14时06分57秒.
Dependencies resolved.
========================================================================================================================
 Package                                 Architecture          Version                      Repository             Size
========================================================================================================================
Installing:
 yum-utils                               noarch                4.0.18-4.el8                 baseos                 71 k
Installing dependencies:
 dbus-glib                               x86_64                0.110-2.el8                  baseos                127 k
 dnf-plugins-core                        noarch                4.0.18-4.el8                 baseos                 69 k
 python3-dateutil                        noarch                1:2.6.1-6.el8                baseos                251 k
 python3-dbus                            x86_64                1.2.4-15.el8                 baseos                134 k
 python3-dnf-plugins-core                noarch                4.0.18-4.el8                 baseos                234 k
 python3-six                             noarch                1.11.0-8.el8                 baseos                 38 k

Transaction Summary
========================================================================================================================
Install  7 Packages

Total download size: 925 k
Installed size: 2.3 M
Downloading Packages:
(1/7): dnf-plugins-core-4.0.18-4.el8.noarch.rpm                                         145 kB/s |  69 kB     00:00
(2/7): dbus-glib-0.110-2.el8.x86_64.rpm                                                 256 kB/s | 127 kB     00:00
(3/7): python3-dateutil-2.6.1-6.el8.noarch.rpm                                          363 kB/s | 251 kB     00:00
(4/7): python3-dbus-1.2.4-15.el8.x86_64.rpm                                             404 kB/s | 134 kB     00:00
(5/7): python3-six-1.11.0-8.el8.noarch.rpm                                              225 kB/s |  38 kB     00:00
(6/7): python3-dnf-plugins-core-4.0.18-4.el8.noarch.rpm                                 536 kB/s | 234 kB     00:00
(7/7): yum-utils-4.0.18-4.el8.noarch.rpm                                                299 kB/s |  71 kB     00:00
------------------------------------------------------------------------------------------------------------------------
Total                                                                                   879 kB/s | 925 kB     00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                1/1
  Installing       : python3-six-1.11.0-8.el8.noarch                                                                1/7
  Installing       : python3-dateutil-1:2.6.1-6.el8.noarch                                                          2/7
  Installing       : dbus-glib-0.110-2.el8.x86_64                                                                   3/7
  Running scriptlet: dbus-glib-0.110-2.el8.x86_64                                                                   3/7
  Installing       : python3-dbus-1.2.4-15.el8.x86_64                                                               4/7
  Installing       : python3-dnf-plugins-core-4.0.18-4.el8.noarch                                                   5/7
  Installing       : dnf-plugins-core-4.0.18-4.el8.noarch                                                           6/7
  Installing       : yum-utils-4.0.18-4.el8.noarch                                                                  7/7
  Running scriptlet: yum-utils-4.0.18-4.el8.noarch                                                                  7/7
  Verifying        : dbus-glib-0.110-2.el8.x86_64                                                                   1/7
  Verifying        : dnf-plugins-core-4.0.18-4.el8.noarch                                                           2/7
  Verifying        : python3-dateutil-1:2.6.1-6.el8.noarch                                                          3/7
  Verifying        : python3-dbus-1.2.4-15.el8.x86_64                                                               4/7
  Verifying        : python3-dnf-plugins-core-4.0.18-4.el8.noarch                                                   5/7
  Verifying        : python3-six-1.11.0-8.el8.noarch                                                                6/7
  Verifying        : yum-utils-4.0.18-4.el8.noarch                                                                  7/7

Installed:
  dbus-glib-0.110-2.el8.x86_64      dnf-plugins-core-4.0.18-4.el8.noarch          python3-dateutil-1:2.6.1-6.el8.noarch
  python3-dbus-1.2.4-15.el8.x86_64  python3-dnf-plugins-core-4.0.18-4.el8.noarch  python3-six-1.11.0-8.el8.noarch
  yum-utils-4.0.18-4.el8.noarch

Complete!

OK,搞定~

相关推荐
Android系统攻城狮5 小时前
Linux Gstreamer深度解析之gst_audio_ring_buffer_delay调用流程与实战(七十二)
linux·运维·服务器·gstreamer音视频·音视频进阶
快乐的韭菜根根5 小时前
ubuntu 安装slurm并配置
linux·运维·ubuntu
倒头就睡的小比特7 小时前
Linux基础指令3
linux·服务器
梦帮科技8 小时前
Kali Linux Scapy 畸形报文构造学——深度解剖非法 TCP Flags 与反常序列号
linux·爬虫·神经网络·算法·数学建模·系统架构·模拟退火算法
半杯咖啡半行码9 小时前
Linux 驱动开发入门:内核模块编程基础
linux·服务器·网络
别动我齐刘海9 小时前
Linux 系统调试学习2
linux·运维·c++·人工智能·学习·机器学习·机器人
龙虾电话9 小时前
语音机器人打断不进去:VAD 双阈值迟滞里一个共用的 bool,和它引发的连锁误判
linux
honsor9 小时前
机房IP化改造首选:以太网温湿度传感器,PoE供电+Modbus TCP一网搞定
linux·运维·服务器
默|笙10 小时前
【Linux网络】_udp_socket(认识)
linux·网络·udp
程序员梅雨10 小时前
ZooKeeper面经总结
java·大数据·linux·分布式·后端·zookeeper·中间件