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/"
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.

安装

安装locales包(如果尚未安装):

sudo apt-get update  
sudo apt-get install locales
  • 1.
  • 2.

安装完locales包后,需要重新生成locale数据

编辑/etc/locale.gen文件,将 zh_CN.UTF-8 前面的注释(#)移除

vi /etc/locale.gen
  • 1.

运行sudo locale-gen来生成这些locale

root@debian:/# sudo locale-gen
Generating locales (this might take a while)...
  zh_CN.UTF-8... done
Generation complete.
  • 1.
  • 2.
  • 3.
  • 4.

设置默认locale:

编辑/etc/default/locale文件,设置LANG为 zh_CN.UTF-8。

vi /etc/default/locale
  • 1.
#  File generated by update-locale
LANG="zh_CN.UTF-8"
  • 1.
  • 2.

重新登录或重启:

为了使新的locale设置生效,您可能需要注销并重新登录或重启系统。

再次尝试重新配置locales(如果需要):

如果您之前试图运行sudo dpkg-reconfigure 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
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.

解决

运行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
  • 1.
  • 2.
  • 3.
  • 4.

解决

运行sudo locale-gen来生成这些locale