Windows subsystem for Linux 汉字不显示

📅 2026/7/8 21:23:11 👁️ 阅读次数 📝 编程学习
Windows subsystem for Linux 汉字不显示

I installed ubuntu 26.04 subsystem, but it doesn't display chinese characters properly.

中国 became

''$'\344\270\255\345\233\275''.txt'

 

 

This issue occurs because the environment isn't correctly interpreting UTF-8 encoded characters, causing the shell to display the octal representation of the bytes (e.g., \344\270\255 for "中").

Since you are using a fresh Ubuntu 26.04 instance, the locale is likely set to a minimal configuration. Here is how to fix it:

1. Generate and Set the Locale

First, ensure that the language packs and UTF-8 locales are generated. Run these commands in your Ubuntu terminal:

Bash
 
# Update the package list
sudo apt update# Install language packs
sudo apt install language-pack-zh-hans# Generate the locale
sudo locale-gen zh_CN.UTF-8# Set the system-wide locale
sudo update-locale LANG=zh_CN.UTF-8

2. Configure Your Shell Environment

Even if the system locale is set, your current shell session might need a nudge. Add the following lines to your ~/.bashrc (or ~/.zshrc if you use Zsh):

Bash
 
export LANG=zh_CN.UTF-8
export LANGUAGE=zh_CN:zh
export LC_ALL=zh_CN.UTF-8

After saving the file, apply the changes by running:

source ~/.bashrc

 

这时系统被设置成了中文,如果不满意,可以改为en_US

# Generate the locale
sudo locale-gen en_US.UTF-8# Set the system-wide locale
sudo update-locale LANG=en_US.UTF-8