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

相关推荐
网络研究院6 分钟前
针对 Linux SSH 服务器的新攻击:Supershell 恶意软件危害易受攻击的系统
linux·服务器·ssh·系统·攻击·恶意软件·危害
imc.111 小时前
初识linux(2)
java·linux·数据库
再拼一次吧1 小时前
Linux软件安装
linux·运维·服务器
请不要叫我菜鸡1 小时前
Go语言基础学习02-命令源码文件;库源码文件;类型推断;变量重声明
linux·后端·golang·类型推断·短变量·变量重声明·库源码文件
路溪非溪1 小时前
Linux内核移植实战总结
linux·运维·服务器
yy_xzz2 小时前
关于交叉编译移植到Debian开发板的一些随笔
linux·qt·debian
琴剑飘零西复东2 小时前
Linux环境中如何快速修改 JAR 包中的配置文件
linux·pycharm·jar
是小赵鸭.2 小时前
云计算实训50——Kubernetes基础命令、常用指令
linux·深度学习·容器·kubernetes·云计算·学习方法
NiNg_1_2342 小时前
Linux中Hadoop常用命令
linux·运维·hadoop
图灵苹果3 小时前
【CentOS 7 】设置密码命令
linux·运维·centos