编程向左,人生向右

去发现,去追求

使用ssh登录server后终端下显示中文乱码

问题:

使用ssh登录server后,终端下显示中文乱码。 本地系统:ubuntu locale problem

查看

在命令行下用locale命令看一下,出现 Cannot set LC_CTYPE to default locale 的错误:

终端中运行locale命令可以看到错误信息
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$ locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LANGUAGE=en_US:
LC_CTYPE=zh_CN.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=

解决方法:

两条命令:

重新生成zh_CN.UTF-8 的locale
1
2
3
4
$ sudo locale-gen zh_CN.UTF-8
Generating locales...
zh_CN.UTF-8... done
Generation complete.
重新配置locale
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$ sudo dpkg-reconfigure locales
Generating locales...
en_AG.UTF-8... done
en_AU.UTF-8... done
en_BW.UTF-8... done
en_CA.UTF-8... done
en_DK.UTF-8... done
en_GB.UTF-8... done
en_HK.UTF-8... done
en_IE.UTF-8... done
en_IN.UTF-8... done
en_NG.UTF-8... done
en_NZ.UTF-8... done
en_PH.UTF-8... done
en_SG.UTF-8... done
en_US.UTF-8... done
en_ZA.UTF-8... done
en_ZM.UTF-8... done
en_ZW.UTF-8... done
zh_CN.UTF-8... up-to-date
Generation complete.

最终效果:

locale solved

Comments