Linux下locale: Cannot set LC_CTYPE to default locale: No such file or directory警告

在Linux下使用locale命令提示如下警告:

locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=zh_CN.UTF-8
LANGUAGE=zh_CN:zh
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC=zh_CN
LC_TIME=zh_CN
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY=zh_CN
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER=zh_CN
LC_NAME=zh_CN
LC_ADDRESS=zh_CN
LC_TELEPHONE=zh_CN
LC_MEASUREMENT=zh_CN
LC_IDENTIFICATION=zh_CN
LC_ALL=

然后,我使用locale -a命令查看了系统安装的字符编码:

locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_COLLATE to default locale: No such file or directory
C
C.UTF-8
POSIX
en_US.utf8
zh_CN
zh_CN.gb2312

发现问题是,我系统上设置的是字符编码是zh_CN.UTF-8,而系统并没有安装zh_CN.UTF-8字符编码。


解决方案:

使用sudo locale-gen zh_CN.UTF-8安装该编码类型,问题解决。






下面说说,怎么在命令行修改字符编码,这里讲中文修改为英文。

1. 编辑配置文件,将zh_CN.UTF-8改为en_US.UTF-8,zh_CN改为en_US。

sudo vim /etc/default/locale
:%s/zh_CN/en_US/g

2. 使用sudo locale-gen en_US.UTF-8命令重新编译该字符编码。



跟系统字符编码设置有关的另一个问题:ls: error initializing month strings

解决方法:sudo vim /etc/default/locale

LANG="zh_CN.UTF-8"
LANGUAGE="zh_CN:zh"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF8"
LC_MONETARY="zh_CN"
LC_PAPER="zh_CN"
LC_NAME="zh_CN"
LC_ADDRESS="zh_CN"
LC_TELEPHONE="zh_CN"
LC_MEASUREMENT="zh_CN"
LC_IDENTIFICATION="zh_CN"

红色部分保证后面带有 .UTF-8

你可能感兴趣的:(linux,编码)