Ubuntu Server 24.04 安装中文,汉字

  


# 1. 更新源
sudo apt update

# 2. 安装中文语言包
sudo apt install -y language-pack-zh-hans language-pack-zh-hans-base

# 3. 生成中文 locale
sudo locale-gen zh_CN.UTF-8

# 4. 设置默认locale( 一直按向下的箭头,选  zh_CN.UTF-8,按空格,出现*,为选中)
sudo dpkg-reconfigure locales

# 5. 安装中文字体
sudo apt install -y fonts-wqy-microhei fonts-wqy-zenhei fonts-noto-cjk
 

 

===========================

Ubuntu 24.04 Server 装完中文汉字乱码终极解决(可行

 
 

第一步:先装全套中文字体(最关键)

 
服务器默认没中文字体,所以汉字方框 / 乱码: 
sudo apt update
sudo apt install -y fonts-wqy-microhei fonts-wqy-zenhei fonts-noto-cjk
 
 

第二步:强制生成并设置中文 UTF-8 locale

 

1. 重新生成中文区域 

sudo locale-gen zh_CN.UTF-8
 
 

2. 配置默认 locale 

sudo dpkg-reconfigure locales  
弹出界面操作:
 
  1. 上下箭头找到  zh_CN.UTF-8空格选中(出现*为选中),回车,
  2. 下一界面选 zh_CN.UTF-8 作为默认
  3. 回车确认
 

第三步:临时生效 + 重启系统

# 临时加载环境变量
export LANG=zh_CN.UTF-8
export LC_ALL=zh_CN.UTF-8

# 重启
sudo reboot 
 

第四步:检查是否配置成功

 
重启后输入: 
locale
 
正常结果必须全是zh_CN.UTF-8
 
如果还是 en_US 就是没配置对,重新走第二步。
 
 

第五步:如果是文件本身编码乱码(GBK/GB2312 文件)

 
Windows 拷过来的文件很多是 GBK 编码,Linux 默认 UTF-8 会乱码。
 

安装编码转换工具 

sudo apt install -y convmv
 
 

把整个文件夹 GBK 转 UTF-8 

# 进入你的文件目录
cd 你的文件夹路径
# 批量转码 GBK → UTF-8
convmv -f GBK -t UTF-8 -r --notest *
 
 

第六步:远程终端(Xshell/CRT)也要改

 
如果你是远程 SSH 看文件乱码
 
  • Xshell / 终端软件 → 编码设置改成 UTF-8
     
    改完重新连接就正常。
 

 

posted @ 2026-05-02 12:04  emanlee  阅读(229)  评论(0)    收藏  举报