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
# 注意,这时给Ubuntu系统用的,如果是raspberry pi使用的Debian系统,往下面看。 # Generate the locale sudo locale-gen zh_CN.UTF-8 # Set the system-wide locale sudo update-locale LANG=zh_CN.UTF-8


这时系统locale被设置成了中文,这时候,如果还想恢复英文显示,可以改为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

 

 

下面的这2步,可以不用管了。

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

 

 

 

=======如何在RASPBERRY PI上使用=====================

 

Ah, the classic flavor of OS confusion!

The language-pack-zh-hans package is specific to Ubuntu. Since Raspberry Pi OS is based on Debian, that package simply doesn't exist in your system's repositories—which is why apt is throwing that "Unable to locate package" error.

On Raspberry Pi OS, managing languages is handled differently. You don't need to download an external package; you just need to generate and activate the Chinese locale built into the system.

Here is the cleanest way to get Chinese working on your Raspberry Pi 4B.

Method 1: The Quick Visual Way (Recommended)

If you have a desktop environment or are connected via SSH/Terminal, you can use the built-in Raspberry Pi configuration tool.

  1. Run the configuration tool:

    Bash
     
    sudo raspi-config
    
  2. Navigate to 5 Localisation Options (or Localisation Options depending on your OS version) using your arrow keys and hit Enter.

  3. Select L1 Locale.

  4. Scroll down until you find zh_CN.UTF-8 UTF-8. Press the Spacebar to select it (an asterisk * will appear next to it).

  5. Hit Enter to proceed.

  6. The system will ask you to select the default locale. Choose zh_CN.UTF-8 if you want the whole system in Chinese, or keep en_US.UTF-8 / en_GB.UTF-8 if you just want English menus but want the system to support Chinese rendering.

  7. Select Finish and let the system reboot.

Method 2: The Command Line Way

If you prefer doing it purely through terminal commands, follow these steps:

  1. Open the locale generator file:

    Bash
     
    sudo nano /etc/locale.gen
    
  2. Scroll down until you find the line # zh_CN.UTF-8 UTF-8.

  3. Uncomment it by deleting the # character at the beginning of the line.

  4. Save and exit (Press Ctrl + O, Enter, then Ctrl + X).

  5. Generate the new language files:

    Bash
     
    sudo locale-gen
    

If you want to set Chinese as your global default system language, run:

Bash
 
sudo update-locale LANG=zh_CN.UTF-8

Crucial Extra Step: Install Chinese Fonts

Even after generating the locale, your Raspberry Pi might show weird boxes (often called "tofu") instead of Chinese characters because it lacks the actual fonts. Run this to fix it:

Bash
 
sudo apt update
sudo apt install fonts-wqy-zenhei fonts-wqy-microhei

Once you finish these steps and reboot (sudo reboot), your Pi will perfectly understand and display Simplified Chinese! Let me know if you run into any issues during the setup.

 

 

posted @ 2026-05-14 02:21  profesor  阅读(45)  评论(0)    收藏  举报