问题描述

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

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

解决办法

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

# 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

# source /etc/profile.d/locale.sh
# source /etc/locale.conf
# source /etc/sysconfig/i18n
# source /etc/environment

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

# 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

# source /etc/profile.d/locale.sh
# source /etc/locale.conf
# source /etc/sysconfig/i18n
# source /etc/environment