修改Linux系统为中文字符编码格式
1.查看当前编码
[root@centos ~]# locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
2.修改/etc/locale.conf配置
原配置: LANG="en_US.UTF-8"
修改为: LANG="zh_CN.UTF-8"
输入: source /etc/locale.conf
[root@centos ~]# source /etc/locale.conf
3.reboot重启后系统后,输入locale再次查看
如果没有下面No such file or directory报错信息就修改成功了,如果有报错信息则继续往下走
[root@centos temp]# reboot
[root@centos ~]# 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
LANG=zh_CN.UTF-8
LC_CTYPE="zh_CN.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=
4.安装语言包
1.langpacks-zh_CN-1.0-12.el8.noarch.rpm
2.glibc-langpack-zh-2.28-164.el8.x86_64.rpm
3.glibc-locale-source-2.28-164.el8.x86_64.rpm
安装指令:rpm -ivh *.rpm --force --nodeps (nodeps的意思是忽视依赖关系。因为各个软件之间会有多多少少的联系。有了这两个设置选项就忽略了这些依赖关系,强制安装或者卸载 )
[root@centos temp]# rpm -ivh glibc-langpack-zh-2.28-164.el8.x86_64.rpm --force --nodeps
warning: glibc-langpack-zh-2.28-164.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:glibc-langpack-zh-2.28-164.el8 ################################# [100%]
[root@centos temp]# rpm -ivh glibc-locale-source-2.28-164.el8.x86_64.rpm --force --nodeps
warning: glibc-locale-source-2.28-164.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:glibc-locale-source-2.28-164.el8 ################################# [100%]
[root@centos temp]# rpm -ivh langpacks-zh_CN-1.0-12.el8.noarch.rpm --force --nodeps
warning: langpacks-zh_CN-1.0-12.el8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:langpacks-zh_CN-1.0-12.el8 ################################# [100%]
5.reboot重启后系统后,输入locale再次查看
[root@centos temp]# reboot
[root@centos ~]# locale
LANG=zh_CN.UTF-8
LC_CTYPE="zh_CN.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=
6.输入date查看是否为中文格式日期
[root@centos ~]# date
2023年 03月 24日 星期五 18:21:01 CST