在 Debian 环境中出现中文乱码,通常不是“系统不支持中文”,而是字符集 / 字体 / 终端编码不一致导致的。下面按常见原因和解决办法说明。
Debian 默认可能使用:
POSIX
C
而不是:
zh_CN.UTF-8
检查当前 locale:
locale
如果看到:
LANG=
LC_ALL=
或不是 UTF-8,就会乱码。
✅ 解决:
sudo dpkg-reconfigure locales
勾选:
zh_CN.UTF-8
并设为默认。
或手动:
sudo apt install locales
sudo locale-gen zh_CN.UTF-8
在 ~/.bashrc 或 ~/.profile 中添加:
export LANG=zh_CN.UTF-8
export LC_ALL=zh_CN.UTF-8
即使系统是对的,终端软件也要支持 UTF-8。
常见情况:
✅ 检查并设置:
示例(PuTTY):
Window → Translation → Remote character set = UTF-8
系统能识别中文,但没字体显示,也会“乱码/方块”。
安装字体:
sudo apt install fonts-wqy-zenhei
# 或
sudo apt install fonts-noto-cjk
例如文件是 GBK / GB2312。
检查:
file filename
转换:
iconv -f GBK -t UTF-8 old.txt -o new.txt
如 vim:
:set encoding=utf-8
:set fileencoding=utf-8
或:
vim ~/.vimrc
加入:
set encoding=utf-8
locale
echo $LANG
locale charmap
fc-list | grep -i cjk
| 场景 | 原因 |
|---|---|
| SSH 登录中文乱码 | 终端非 UTF-8 |
| 文件 cat 乱码 | 文件编码非 UTF-8 |
| 系统提示中文乱码 | locale 未设置 |
| 显示成方块 | 无中文字体 |
如果你能说一下:
我可以直接给你针对性的一步到位方案。