ubuntu解决终端中文乱码问题

  1. 查看当前系统语言
1
$ echo $LANG
  1. 查看系统安装的语言包
1
2
3
4
5
6
$ locale -a 
C
C.UTF-8
POSIX

$ sudo dpkg -l | grep language-pack-zh-hans
  1. 如果没有中文语言包,需要安装
1
$ sudo apt-get install language-pack-zh-hans
  1. 安装成功后,确认是否安装成功
1
2
3
4
5
6
7
8
9
10
$ 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. 设置系统语言环境
1
2
3
4
5
# export 的方式只对当前终端生效
$ export LANG="zh_CN.UTF-8"

# /etc/profile 文件中添加export LANG="zh_CN.UTF-8" 对所有用户生效
$ sudo vim /etc/profile