Centos: 解决系统编码 locale 的 LC_CTYPE / LC_ALL 问题

96
Tim_Lee
2017.10.20 12:45* 字数 126

0 系统环境

CentOS 7.4

# rpm -q centos-release
centos-release-7-4.1708.el7.centos.x86_64

1 问题

初装的系统,如果输入 locale 查看系统字体编码,可能会出现报错

locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory

或者设置编码不完全时,会出现警告

LC_CTYPE: cannot change locale (UTF-8): No such file or directory

2 解决方法

如果要设置中文版的字体编码。在每个文件中增加以下内容。
中文版

# vim /etc/profile.d/locale.sh
export LC_CTYPE=zh_CN.UTF-8
export LC_ALL=zh_CN.UTF-8

# vim /etc/locale.conf
LANG=zh_CN.UTF-8

# vim /etc/sysconfig/i18n
LANG=zh_CN.UTF-8

# vim /etc/environment
LANG=zh_CN.UTF-8
LC_ALL=zh_CN.UTF-8

英文版本

# vim /etc/profile.d/locale.sh
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

# vim /etc/locale.conf
LANG=en_US.UTF-8

# vim /etc/sysconfig/i18n
LANG=en_US.UTF-8

# vim /etc/environment
LANG=en_US.UTF-8
LC_ALL=en_US.UTF-8

3 参考

CentOS7 LC_CTYPE: cannot change locale (UTF-8): No such file or directory
CentOS cannot change locale UTF-8解决方法及设置中文支持

centos
Web note ad 1