首页 >> IT知识库 >> Linux >>解决Ubuntu 终端显示中文乱码的问题
详细内容

解决Ubuntu 终端显示中文乱码的问题

问题:

Ubuntu 终端显示中文乱码,相关配置和其它服务器都是一样的,不知道这台服务器为什么显示中文乱码。


root@localhost:~# ls -lh /etc/alternatives/vim
lrwxrwxrwx 1 root root 18 68 14:48 /etc/alternatives/vim -> /usr/bin/vim.basic
root@localhost:~# ls -lh /etc/alternatives/vi
lrwxrwxrwx 1 root root 18 68 14:48 /etc/alternatives/vi -> /usr/bin/vim.basic


root@localhost:~# more /etc/default/locale
LANG="zh_CN.UTF-8"
LANGUAGE="zh_CN:zh"
LC_NUMERIC="zh_CN"
LC_TIME="en_US.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
root@localhost:~# echo $LANG
zh_CN.UTF-8

vim /etc/environment // Ubuntu默认的中文字符编码
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
LANG="zh_CN.UTF-8"
LANGUAGE="zh_CN:zh:en_US:en"

vim /var/lib/locales/supported.d/local
zh_CN.UTF-8 UTF-8
en_US.UTF-8 UTF-8
zh_CN.GBK GBK

# locale-gen

vim /etc/default/locale
LANG="zh_CN.UTF-8"
LANGUAGE="zh_CN:zh"
LC_NUMERIC="zh_CN"
LC_TIME="en_US.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"


# reboot

# apt-get update // 此命令测试输出到终端的中文信息还是无法正常显示

回答:问题解决了!找了好几天的资料万变不离其中!最后确认是locale相关变量惹的祸。
root@localhost:~# echo $LC_ALL
zh_CN.GB18030

root@localhost:~# echo $LANG
zh_CN.UTF-8


root@localhost:~# export LC_ALL="" 
root@localhost:~# echo $LC_ALL

root@localhost:~# apt-get update
忽略 http://cn.archive.ubuntu.com saucy InRelease
忽略 http://cn.archive.ubuntu.com saucy-updates InRelease
忽略 http://cn.archive.ubuntu.com saucy-backports InRelease
忽略 http://security.ubuntu.com saucy-security InRelease
命中 http://cn.archive.ubuntu.com saucy Release.gpg

问题解决啦!看到可以正常显示中文了吧!!

但是这样重新启动计算机问题重现了,彻底解决方法:
# vim /etc/profile
export LC_ALL=""
# source /etc/profile

在线客服
- 客户经理
  • 点击这里给我发消息
  • 点击这里给我发消息
技术支持: 建站ABC | 管理登录