current position:Home>Handling of Chinese garbled code in Ubuntu

Handling of Chinese garbled code in Ubuntu

2022-01-26 22:23:13 Yan Long

adopt docker Downloaded a brand new ubuntu Mirror image , After running, it is found that Chinese is displayed as garbled .

$ls
'saas'$'\344\273\243\347\240\201\344\277\256\346\224\271\350\256\260\345\275\225''.txt'

reason :

Generally, there are two reasons for Chinese garbled code :

  1. The default language set does not support displaying Chinese
  2. The Chinese language pack is not installed in the system

Solution

  1. View the current system language
$ echo $LANG

2. Check the language pack installed on the system

$ locale -a 
C
C.UTF-8
POSIX

$ sudo dpkg -l | grep language-pack-zh-hans
  1. If there is no Chinese language pack , Need to install
$ sudo apt-get install language-pack-zh-hans
  1. After successful installation , Confirm whether the installation is successful
$ locale -a 
C
C.UTF-8
POSIX
zh_CN.utf8
zh_SG.utf8

$ sudo dpkg -l | grep language-pack-zh-hans
ii  language-pack-zh-hans           1:20.04+20210802                    all          translation updates for language Simplified Chinese
ii  language-pack-zh-hans-base      1:20.04+20210802                    all          translations for language Simplified Chinese
  1. Set system locale
// export  This method only works for the current terminal 
$ export LANG="zh_CN.UTF-8"

//  /etc/profile  Add... To the file export LANG="zh_CN.UTF-8"  Effective for all users 
$ vim /etc/profile

copyright notice
author[Yan Long],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201262223111358.html

Random recommended