Centos: 解決系統編碼 locale 的 LC_CTYPE / LC_ALL 問題

weixin_34146805發表於2017-10-20

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解決方法及設定中文支援

相關文章