尝试执行
udo update-locale LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8
看是否有报错
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = “zh_CN:zh”,
LC_ALL = “zh_CN.UTF-8”,
LC_CTYPE = “zh_CN.UTF-8”,
LANG = “zh_CN.UTF-8”
are supported and installed on your system.
perl: warning: Falling back to the standard locale (“C”).
*** update-locale: Error: invalid locale settings: LC_ALL=zh_CN.UTF-8 LANG=zh_CN.UTF-8
这个错误非常明确:系统根本没有安装 zh_CN.UTF-8 语言包。所以设置 locale 时一直在报错。
🔧 立即修复(在"不正常"的机器上执行)
步骤1:安装中文语言包
bash
先更新包列表
sudo apt-get update
安装中文语言支持
sudo apt-get install -y language-pack-zh-hans
或者更简单的方法:直接生成中文locale
sudo locale-gen zh_CN.UTF-8
步骤2:验证安装成功
bash
检查 zh_CN.UTF-8 是否已安装
locale -a | grep zh_CN
应该能看到类似这样的输出:
zh_CN.utf8
步骤3:重新设置 locale
bash
重新配置 locales
sudo dpkg-reconfigure locales
在弹出的界面中,用空格键选中 zh_CN.UTF-8,然后 Tab 键选择 OK
如果没有图形界面,可以这样设置:
bash
直接更新配置文件
sudo update-locale LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 LANGUAGE=zh_CN:zh
使配置生效
source /etc/default/locale
步骤4:退出重新登录或重启终端
bash
或者直接切换环境变量测试
export LC_ALL=zh_CN.UTF-8
export LANG=zh_CN.UTF-8
再检查 locale,应该不再报错
locale
评论区