Solution to Chinese garbled characters in Ubuntu system

Solution to Chinese garbled characters in Ubuntu system


Recently, after pulling the Ubuntu image below on docker and running it, I found that there are garbled characters in Chinese. I searched many tutorials on the Internet but failed to solve it. Finally, combined with the results and attempts of many parties, I finally succeeded. I will record it here.

1. Install Chinese language

It's very simple here, and it can be done in one sentence.

apt-get install language-pack-zh-hans* 

2. Install the command locale of the language setting

Here is also a sentence can be done.

apt install locales

3. Install Chinese related fonts

For the situation where Chinese garbled characters are spaces, install Chinese fonts to solve it.

sudo apt-get install fonts-droid-fallback ttf-wqy-zenhei ttf-wqy-microhei fonts-arphic-ukai fonts-arphic-uming

4. Modify the environment variables of the language

4.1 Environment variable 1

This is very important. Many tutorials say to modify under /etc/environment. I modified it, but it didn’t take effect automatically. You have to actively source it to take effect. We don’t do this. We add it at the end of the /root/.bashrc file.

export LANG=zh_CN.UTF-8
export LANGUAGE=zh_CN:zh:en_US:en

4.2 Setting 2

Then modify /var/lib/locales/supported.d/local (create a new file without this file, and add it at the end):

en_US.UTF-8 UTF-8
zh_CN.UTF-8 UTF-8
zh_CN.GBK GBK
zh_CN GB2312

5. Formal configuration language

Use locale to configure language

sudo locale-gen

postscript

After completing the above configuration and re-login to the shell, 90% of the problems of Chinese garbled characters can be solved. It’s not easy to sort out, if you think it’s helpful to you, remember to like, bookmark and follow me, your little support is the motivation for my continuous creation~!

Guess you like

Origin blog.csdn.net/HELLOWORLD2424/article/details/128442204