Fedora-升级之后-setlocale-错误
Fedora-升级之后-setlocale-错误
前言
fedora 40 升级 fedora 41 之后,出现了 setlocale 错误。这个问题通常是由于缺少相应的 locale 配置引起的,可能会导致一些特定命令或应用无法正常工作。升级前已经安装配置了字符集,可能是升级之后执行了 autoremove
之后自动清理了
1
2
3
4
5
6
-bash: warning: setlocale: LC_CTYPE: cannot change locale (en_US.UTF-8): No such file or directory
-bash: warning: setlocale: LC_CTYPE: cannot change locale (en_US.UTF-8): No such file or directory
-bash: warning: setlocale: LC_COLLATE: cannot change locale (en_US.UTF-8): No such file or directory
-bash: warning: setlocale: LC_CTYPE: cannot change locale (en_US.UTF-8): No such file or directory
-bash: warning: setlocale: LC_CTYPE: cannot change locale (en_US.UTF-8): No such file or directory
-bash: warning: setlocale: LC_COLLATE: cannot change locale (en_US.UTF-8): No such file or directory
解决方法
检查 locale 配置
检查系统上是否已经安装了所需的 locale。可以通过以下命令查看已安装的 locale:
1
2
3
4
5
6
locale -a
┌─[wxj@DarkStar]─[~]
└──╼ $ locale -a
C
C.utf8
POSIX
确保在输出中能够找到 “en_US.UTF-8”,如果没有,我们需要添加这个 locale。
安装缺失的 locale
使用以下命令安装缺失的 locale(以”en_US.UTF-8”为例),提示缺少什么字符集就安装什么:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 安装缺失的 locale
sudo dnf install glibc-langpack-en
┌─[wxj@DarkStar]─[~]
└──╼ $ sudo dnf install -y glibc-langpack-en
Updating and loading repositories:
Repositories loaded.
Package Arch Version Repository Size
Installing:
glibc-langpack-en x86_64 2.40-21.fc41 updates 5.7 MiB
Transaction Summary:
Installing: 1 package
Total size of inbound packages is 641 KiB. Need to download 641 KiB.
After this operation, 6 MiB extra will be used (install 6 MiB, remove 0 B).
[1/1] glibc-langpack-en-0:2.40-21.fc41.x86_64 100% | 862.2 KiB/s | 640.6 KiB | 00m01s
[1/1] Total 100% | 667.3 KiB/s | 640.6 KiB | 00m01s
Running transaction
[1/3] Verify package files 100% | 333.0 B/s | 1.0 B | 00m00s
[2/3] Prepare transaction 100% | 6.0 B/s | 1.0 B | 00m00s
[3/3] Installing glibc-langpack-en-0:2.40-21.fc41.x86_64 100% | 42.5 MiB/s | 5.8 MiB | 00m00s
Complete!
安装之后重新登陆就不会再提示错误,如果想要指定对应的系统 locale,可以按照以下步骤设置,保持默认的配置就不需要再执行以下操作了
更新配置
更新系统配置,使新的 locale 生效:
1
sudo localectl set-locale LANG=en_US.UTF-8
重启系统
为了确保 locale 的改变生效,重新启动系统:
1
sudo reboot
验证
重新登录系统后,再次运行 locale 命令,确保 “en_US.UTF-8” 出现在列表中。
1
locale
之后就不会收到 “cannot change locale” 的错误提示
本文由作者按照
CC BY 4.0
进行授权