Problem Overview
On Ubuntu systems, incorrect locale configuration can cause garbled characters in terminal output, filenames, or application interfaces. This guide explains how to add full Chinese language support to Ubuntu.
Check Installed Language Packs
First, check which locales are already installed on your system.
locale -a
If the output includes zh_CN.utf8 or similar entries, Chinese language packs are partially installed.
Install Chinese Language Packs
Method 1: Using locale-gen (Recommended)
This is the traditional method for configuring system-wide locales.
-
Edit the locale generation configuration file:
sudo vi /etc/locale.genOr use your preferred text editor (e.g.,
nano). -
Find and uncomment (remove the
#from) the following lines (or similar):# zh_CN.UTF-8 UTF-8Note: Modern Ubuntu systems should use
zh_CN.UTF-8. Other encodings like GBK are for legacy compatibility and are not recommended. -
Generate the enabled locales:
sudo locale-gen
Method 2: Interactive Configuration with dpkg-reconfigure locales
This tool provides an interactive menu for selecting and generating locales.
sudo dpkg-reconfigure locales
After running the command:
- Use the spacebar to select
zh_CN.UTF-8from the list. - Press Tab to move to
<Ok>and press Enter. - In the next screen, select
zh_CN.UTF-8as the default system locale and confirm.
Set the System Default Locale
After installing the language pack, configure the system's default locale. Edit the file:
sudo vi /etc/default/locale
Ensure its contents are similar to the following (recommended settings):
LANG="zh_CN.UTF-8"
LANGUAGE="zh_CN:zh"
Note: Setting LC_ALL overrides all other locale variables. For most users, setting LANG and LANGUAGE is sufficient.
Configure the Shell Environment for the Current User
System settings may not apply immediately to your current session. Add the environment variables to your shell configuration file (e.g., ~/.bashrc or ~/.profile).
Add these lines at the end of the file:
export LANG=zh_CN.UTF-8
export LANGUAGE=zh_CN:zh
Then apply the changes:
source ~/.bashrc
Verification and Activation
-
Verify Configuration: Open a new terminal and run:
localeAll variables should show
zh_CN.UTF-8or similar values. -
Install Chinese Input Method (Optional): Desktop users may need an input method framework, e.g.:
sudo apt install fcitx5 fcitx5-chinese-addons -
Reboot: For all system services and the graphical interface to load the new settings, a reboot is recommended.
sudo reboot
Troubleshooting
- Command Not Found: If
locale-genordpkg-reconfigureis missing, install thelocalespackage:sudo apt install locales. - GUI Not Switched: For Ubuntu Desktop, use the "Region & Language" tool in System Settings for automatic dependency and font handling.
- Garbled Characters Persist: Ensure your terminal emulator's encoding is set to UTF-8 and that files are saved in UTF-8 encoding.
Best Practice: On servers, install only the
zh_CN.UTF-8locale to avoid encoding complexity. On desktops, install the full Chinese support package:sudo apt install language-pack-zh-hans.