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,搞定~

相关推荐
爱瑞瑞2 分钟前
🐧深入浅出的认识 Linux 指令
linux·shell
ajassi200015 分钟前
开源 java android app 开发(十一)调试、发布
android·java·linux·开源
小李飞刀李寻欢41 分钟前
使用kubeadm部署Kubernetes(k8s)集群的步骤
linux·服务器·ubuntu·kubernetes·k8s
运维成长记1 小时前
阿里云实践创建实例步骤
linux·运维·服务器·阿里云·云计算
THe CHallEnge of THe BrAve1 小时前
Linux检验库是否安装成功
linux·运维·服务器
算家计算2 小时前
告别复杂文档解析噩梦!MonkeyOCR 本地部署教程:支持公式/表格多元素结构化
linux·人工智能·开源
曹勖之3 小时前
ROS2 工作空间中, CMakeLists.txt, setup.py和 package.xml的作用分别是?
xml·linux·服务器·ros2
企鹅侠客3 小时前
ttyd:安全地通过网络共享您的 Linux 终端
linux·运维·ttyd
饭碗、碗碗香4 小时前
【开发常用命令】:服务器与本地之间的数据传输
linux·运维·服务器·笔记·学习
MonkeyBananas5 小时前
在Ubuntu中使用Apache2部署项目
linux·运维·ubuntu