How to solve the Chinese garbled problem in centos7

hzc
Release: 2020-06-17 10:40:35
Original
6163 people have browsed it

How to solve the Chinese garbled problem in centos7Check whether the Chinese package is installed

You can use the following naming to check whether the Chinese installation package is installed on the system.

locale -a |grep "zh_CN"
Copy after login

There is no output, indicating that it is not installed. Enter the following command to install:

yum groupinstall "fonts" -y
Copy after login

The installation is complete, check which Chinese language packs are installed

[root@iz2ze6adlpez0gy7j13vrmz /]# locale -a | grep "zh_CN"
zh_CN
zh_CN.gb18030
zh_CN.gb2312
zh_CN.gbk
zh_CN.utf8
Copy after login

Indicates that the Chinese language pack has been installed on the system and there is no need to install it again. Important note, if your system still cannot use Chinese after following the steps below, please try the above encoding methods one by one. For example, change LANG="zh_CN" to LANG="zh_CN.gb18030".

2 Modify the configuration file

Before modifying the configuration file, let’s take a look at the current system language environment:

# echo $LANG
en_US.UTF-8

# 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=
Copy after login

Although the Chinese language pack is installed However, the language environment of this machine is not Chinese. You need to modify the locale.conf configuration file

# vim /etc/locale.conf
LANG="zh_CN"
# source   /etc/locale.conf
Copy after login
vim /etc/locale.conf 进入编辑页面,输入i开始编辑,编辑完成输入esc到底行模式,然后输入:wq,保存并退出
Copy after login

You can also use the command to modify the locale.conf configuration file:

#  localectl set-locale LANG=zh_CN
Copy after login

Check the current locale afterwards:

# echo $LANG
zh_CN
# locale
LANG=zh_CN
LC_CTYPE="zh_CN"
LC_NUMERIC="zh_CN"
LC_TIME="zh_CN"
LC_COLLATE="zh_CN"
LC_MONETARY="zh_CN"
LC_MESSAGES="zh_CN"
LC_PAPER="zh_CN"
LC_NAME="zh_CN"
LC_ADDRESS="zh_CN"
LC_TELEPHONE="zh_CN"
LC_MEASUREMENT="zh_CN"
LC_IDENTIFICATION="zh_CN"
LC_ALL=
Copy after login

3. Verification is successful

[root@node2 ~]# date
2017年 10月 16日 星期一 16:30:24 CST
Copy after login

4. Supplementary explanation of the command

locale -a |grep "zh_CN": List the names of all available public locales, and then filter Chinese

locale -a: List the names of all available public language environments.

If you can see the following items, it also means that the system has installed the Chinese language pack. No need to install anymore, so what do these items mean?

##{Language code}_{Country code}.{Character set}

zh is Chinese The code name, CN is the code name of China, gb18030, gb2312, utf8 is the language character set

Then each item can be commonly understood as "You speak Chinese, you are in China, language The character set is gb18030/gb2312/utf8”

If the above items are not found, manually install the Chinese language pack

# yum install kde -l10n-Chinese (about 11M)

locale: View the current system language environment

How to solve the Chinese garbled problem in centos7

The meaning of each item is:

LANG: The language of the current system

LC_CTYPE: Language symbols and their classification

LC_NUMERIC: Numbers

LC_COLLATE: Comparison and sorting habits

LC_TIME: Time display format

LC_MONETARY: Currency unit

LC_MESSAGES: Information mainly includes prompt information, error information, status information, titles, labels, buttons and menus, etc.

LC_NAME: Name writing method

LC_ADDRESS:Address writing method

LC_TELEPHONE:Phone number writing method

LC_MEASUREMENT:Weights and measures expression

LC_PAPER: Default paper size

LC_IDENTIFICATION: Overview of the information contained in the locale itself

LC_ALL: The variable with the highest priority. If this variable is set, all LC_* and LANG variables will be forced to follow its value

We see that although the Chinese language pack is installed, the locale of the local machine is not Chinese

Restart the system

# reboot
Copy after login

5. Solve the garbled problem of remote tool SSH Secure

Use remote tools When connecting, if Linux has Chinese files or directories, garbled characters will appear during display. The reason is that the Linux encoding is UTF-8, and the remote tool defaults to the current system local encoding, which is GBK. So the solution is to unify the encoding of both. However, the SSH Secure tool cannot set the encoding, so the encoding is unified by modifying the system encoding of Linux.


Step one: Check the locale of the current system.

This is because it has been modified to gbk encoding before.

Step 2: Modify the configuration file locale.conf

# vim /etc/locale.conf
Copy after login
Enter i to enter the editing mode. After editing, press ESC to enter the bottom line mode. Then enter: wq to exit and save.

执行下面的命令,让修改生效。

# source /etc/locale.conf
Copy after login

输入date验证。如果还有问题,也可以reboot重启一下。

推荐教程: 《CentOS教程

The above is the detailed content of How to solve the Chinese garbled problem in centos7. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!