CentOS
1)用命令查看当前使用的语言包:
locale
2)用命令查看服务器当前已安装的语言包:
locale -a
3)查看查询结果中是否有zh_CN,如果没有,则需要安装
yum install kde-l10n-Chinese
4)永久性设置
localectl set-locale LANG=zh_CN.UTF-8
Debian
系统环境
root@debian:~# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
安装
安装locales包(如果尚未安装):
sudo apt-get update
sudo apt-get install locales
安装完locales包后,需要重新生成locale数据
编辑/etc/locale.gen文件,将 zh_CN.UTF-8 前面的注释(#)移除
vi /etc/locale.gen
运行sudo locale-gen来生成这些locale
root@debian:/# sudo locale-gen
Generating locales (this might take a while)...
zh_CN.UTF-8... done
Generation complete.
设置默认locale:
编辑/etc/default/locale文件,设置LANG为 zh_CN.UTF-8。
vi /etc/default/locale
# File generated by update-locale
LANG="zh_CN.UTF-8"
重新登录或重启
再次尝试重新配置locales(如果需要)
问题
locales is not installed
root@debian:/opt/mysql/openssl-1.1.1w# sudo dpkg-reconfigure locales
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "zh_CN.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
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
dpkg-query: package 'locales' is not installed and no information is available
Use dpkg --info (= dpkg-deb --info) to examine archive files.
/usr/sbin/dpkg-reconfigure: locales is not installed
解决
运行sudo apt-get install locales
Cannot set LC_CTYPE to default locale: No such file or directory
Cannot set LC_MESSAGES to default locale: No such file or directory
Cannot set LC_ALL to default locale: No such file or directory
root@debian:/# 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
解决
运行sudo locale-gen来生成这些locale