- 1 1. Introduction
- 2 2. Main Causes of Garbled Text
- 3 3. Checking and Fixing Locale Settings
- 4 4. Installing and Configuring Japanese Fonts
- 5 5. Checking and Converting Character Encoding
- 6 6. Checking Terminal and Editor Settings
- 7 7. Solutions for Specific Cases
- 8 8. FAQ (Frequently Asked Questions)
- 8.1 Q1. I configured the locale correctly, but garbled text still appears.
- 8.2 Q2. Only certain files show garbled text.
- 8.3 Q3. I cannot input Japanese characters in the terminal.
- 8.4 Q4. Japanese text is garbled in WSL.
- 8.5 Q5. Japanese text is garbled inside a Docker container.
- 8.6 Q6. GUI menus and dialogs show corrupted Japanese text.
- 9 9. Summary
- 10 Conclusion
1. Introduction
When using Ubuntu, you may occasionally encounter garbled characters. These issues can appear in various situations, such as terminal output, displaying Japanese filenames, or viewing Japanese web pages in a browser. In many cases, Japanese text may not display correctly with the default configuration, making proper setup essential.
This article explains the causes of garbled text in Ubuntu and provides concrete solutions to resolve them. This guide is intended for the following users:
- Beginners who are using Ubuntu without configuring Japanese language support
- Users who want to understand the root cause of garbled characters and seek fundamental solutions
- Users experiencing garbled text in terminal or GUI environments and want to know how to fix it
Let’s begin by reviewing the primary causes of garbled text in Ubuntu.
2. Main Causes of Garbled Text
Incorrect Locale Settings
The locale in Ubuntu defines system settings related to language, date format, and other regional behaviors. When these settings are incorrect, Japanese text may not display properly, resulting in garbled characters.
For example, if running the locale command shows values like “C” or “POSIX,” the system locale is not configured properly:
$ locale
LANG=C
LC_ALL=
Ideally, a Japanese environment should show settings such as LANG=ja_JP.UTF-8.
Missing or Unconfigured Fonts
In some default Ubuntu installations, Japanese fonts may not be available, causing Japanese text to display as empty squares (□) or unreadable symbols.
This issue typically occurs in the following scenarios:
- Menu items and buttons in GUI applications appear corrupted
- Opening Japanese text in a text editor shows garbled characters
Mismatched Character Encoding
Ubuntu primarily uses UTF-8 encoding. When opening files encoded in Shift_JIS or EUC-JP—common in legacy Windows or UNIX systems—text corruption may occur.
Typical issues include:
- Text editors display strange symbols when opening Japanese files
- Output from the
catcommand appears broken in the terminal
Terminal or Editor Misconfiguration
Even if files are correctly encoded in UTF-8, misconfigured terminal or editor settings can still cause display issues.
- The terminal encoding is set to something other than
UTF-8 - Editors like Vim or VSCode fail to auto-detect character encoding
- Japanese characters appear as “?” or “◇” when viewed via
lessorcat
3. Checking and Fixing Locale Settings
How to Check Locale Settings
To check your current locale configuration, run the command below:
locale
Example output:
LANG=C
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_PAPER="C"
LC_NAME="C"
LC_ADDRESS="C"
LC_TELEPHONE="C"
LC_MEASUREMENT="C"
LC_IDENTIFICATION="C"
LC_ALL=
In this case, LANG=C indicates that Japanese support is not enabled. For a proper Japanese configuration, you should see values such as:
LANG=ja_JP.UTF-8
LC_ALL=ja_JP.UTF-8
Installing and Setting the Japanese Locale
1. Check and Add the Japanese Locale
To confirm whether the Japanese locale is available in your system, run the following command:
locale -a | grep ja_JP
Example output:
ja_JP.eucJP
ja_JP.utf8
If ja_JP.utf8 is not listed, you must install the Japanese locale package.
Install it using the following commands:
sudo apt update
sudo apt install -y language-pack-ja
Then enable the locale:
sudo locale-gen ja_JP.UTF-8
sudo update-locale LANG=ja_JP.UTF-8
2. Apply the Locale System-Wide
To apply the locale change across the entire system, run the following commands:
export LANG=ja_JP.UTF-8
export LC_ALL=ja_JP.UTF-8
To make these changes persistent, add them to ~/.bashrc or ~/.profile:
echo 'export LANG=ja_JP.UTF-8' >> ~/.bashrc
echo 'export LC_ALL=ja_JP.UTF-8' >> ~/.bashrc
source ~/.bashrc
If you want to apply the settings to all users, edit the following file instead:
sudo nano /etc/default/locale
Add or update the following entries:
LANG=ja_JP.UTF-8
LC_ALL=ja_JP.UTF-8
To apply the settings, log out and log back in, or reboot the system.
4. Installing and Configuring Japanese Fonts
Why Japanese Fonts Are Necessary
In a default Ubuntu environment, Japanese fonts may not be installed. Without them, Japanese text appears as empty squares or unintelligible symbols.
You can confirm missing fonts in the following situations:
- Menu labels and GUI buttons display garbled characters
- Japanese text appears corrupted when opened in a text editor
Recommended Japanese Fonts
The following Japanese fonts are available for use in Ubuntu:
| Font Name | Description |
|---|---|
| Noto Sans CJK JP | A high-quality Japanese font provided by Google (recommended as default) |
| Takao Fonts | The former default fonts in Ubuntu, available in regular and bold styles |
| IPA Fonts | High-quality fonts provided by the Information-technology Promotion Agency (IPA) |
| VL Gothic (VLゴシック) | Highly readable, ideal for terminal environments |
How to Install Japanese Fonts
1. Noto Sans CJK JP (Recommended Default)
sudo apt update
sudo apt install -y fonts-noto-cjk
2. Takao Fonts
sudo apt install -y fonts-takao
3. IPA Fonts
sudo apt install -y fonts-ipafont
4. VL Gothic (for Terminal Use)
sudo apt install -y fonts-vlgothic
Once installation is complete, restart the system or refresh the font cache:
fc-cache -fv
How to Configure Fonts
Configuring Fonts in GUI Applications
- Open the “Settings” application
- Navigate to the “Fonts” section
- Change “Standard Font,” “Document Font,” and “Monospace Font” to your preferred fonts
- Log out and log back in to apply the changes
Configuring Fonts in the Terminal
- Open the terminal
- Select “Preferences” from the menu
- Open the “Profile” settings and enable “Use custom font”
- Select your preferred font (e.g., Noto Sans Mono CJK JP)
- Save the settings and restart the terminal
Verify Font Configuration
To confirm that fonts have been applied correctly, try the following steps:
- Check installed fonts using
fc-list
fc-list | grep "Noto"
- Verify Japanese display in the terminal
echo "こんにちは、Ubuntuの文字化け対策"
- Confirm Japanese text rendering in GUI applications such as Firefox or LibreOffice
5. Checking and Converting Character Encoding
What Is Character Encoding?
Character encoding defines how characters are represented digitally. Common encodings include:
| Encoding | Characteristics | Main Usage |
|---|---|---|
| UTF-8 | Multi-language support; standard in Linux | Ubuntu and web development |
| Shift_JIS | Japanese-focused; standard in Windows environments | Windows apps and legacy systems |
| EUC-JP | Previously used in UNIX-based systems | Older Linux distributions |
| ISO-2022-JP | Used in some mail systems | Email communication |
Since Ubuntu uses UTF-8 as the default encoding, opening files encoded in other formats may lead to garbled text.
How to Check a File’s Character Encoding
1. Using the file Command
file -i sample.txt
Example output:
sample.txt: text/plain; charset=iso-8859-1
2. Using the nkf Command
sudo apt install -y nkf
nkf --guess sample.txt
Example output:
Shift_JIS (CRLF)
How to Convert Character Encoding
1. Using the iconv Command
Example: Convert Shift_JIS to UTF-8
iconv -f SHIFT_JIS -t UTF-8 sample.txt -o sample_utf8.txt
Example: Convert EUC-JP to UTF-8
iconv -f EUC-JP -t UTF-8 sample.txt -o sample_utf8.txt
2. Using the nkf Command
Example: Convert Shift_JIS to UTF-8
nkf -w sample.txt > sample_utf8.txt
Example: Convert EUC-JP to UTF-8
nkf -w --overwrite sample.txt
Preventing Garbled Text in Terminals and Editors
1. Display Correct Encoding with less
export LESSCHARSET=utf-8
less sample.txt
2. Open Files with Encoding Specified in vim
vim -c "set encoding=utf-8" sample.txt
3. Modify Character Encoding in gedit or VSCode
- gedit (GNOME default editor)
- Open the file using
gedit sample.txt - When saving, select
UTF-8in the “Encoding” dropdown
- VSCode (Visual Studio Code)
- Click the “Encoding” indicator at the bottom of the window
- Select
UTF-8to convert the file

6. Checking Terminal and Editor Settings
Verify and Adjust Terminal Settings
1. Check Terminal Encoding
To confirm your locale settings, run the commands below:
echo $LANG
echo $LC_ALL
Example output (correct configuration)
ja_JP.UTF-8
ja_JP.UTF-8
If the output shows C or POSIX, change the locale to ja_JP.UTF-8.
2. Configure Terminal Fonts
GNOME Terminal (Ubuntu default terminal)
- Open the terminal
- Select “Preferences”
- Open the “Profile” and navigate to the “Text” tab
- Enable “Use custom font” and select one of the following:
- Noto Sans Mono CJK JP
- VL Gothic
- Takao Gothic
- Save your settings and restart the terminal
Configuring Editor Encoding
1. Vim Encoding Settings
Open Vim and run the following commands to check current encoding:
:set encoding?
:set fileencoding?
Example output:
encoding=utf-8
fileencoding=utf-8
If the settings differ from utf-8, update ~/.vimrc with:
set encoding=utf-8
set fileencodings=utf-8,sjis,euc-jp
set fileformats=unix,dos,mac
2. Nano Encoding Settings
To change the default encoding, add the following to ~/.nanorc:
set encoding "utf-8"
3. VSCode Encoding Settings
- Click the “Encoding” indicator at the bottom right
- Select “Reopen with Encoding” and choose
UTF-8 - If needed, select “Save with Encoding”
To set UTF-8 as the default, add the following to settings.json:
"files.encoding": "utf8"
7. Solutions for Specific Cases
Preventing Garbled Text in GUI Applications
1. Japanese Characters Display Incorrectly in Firefox or Chrome
Solution:
- Install the required Japanese fonts
sudo apt install -y fonts-noto-cjk fonts-ipafont
- Check and update browser font settings
- Firefox:
- Visit
about:preferences - Open “Fonts & Colors” → “Advanced”
- Set both “Proportional” and “Monospace” fonts to
Noto Sans CJK JP
- Visit
- Google Chrome:
- Access
chrome://settings/fonts - Change “Standard font” and “Fixed-width font” to
Noto Sans CJK JP
- Access
2. Garbled Text in LibreOffice
Solution:
- Install Japanese fonts such as
fonts-noto-cjkorfonts-ipafont - Change LibreOffice font settings
- Go to “Tools” → “Options” → “LibreOffice” → “Fonts”
- Set the default font to
Noto Sans CJK JP
Preventing Garbled Text in CUI Environments
1. SSH Session Displays Garbled Characters
Solution:
- Check locale on the remote server
locale
- If it is not set to
ja_JP.UTF-8, run the following commands:
sudo apt install -y language-pack-ja
sudo locale-gen ja_JP.UTF-8
sudo update-locale LANG=ja_JP.UTF-8
Preventing Garbled Text in Specific Applications
1. WSL (Windows Subsystem for Linux) Shows Garbled Japanese Text
Solution:
- Configure WSL to use
ja_JP.UTF-8
echo 'export LANG=ja_JP.UTF-8' >> ~/.bashrc
echo 'export LC_ALL=ja_JP.UTF-8' >> ~/.bashrc
source ~/.bashrc
- Set Windows Terminal font to
Noto Sans Mono CJK JP
2. Garbled Japanese Text Inside Docker Containers
Solution:
- Enter the container and check locale
docker exec -it container_name bash
locale
- Add the Japanese locale if missing
apt update && apt install -y locales
locale-gen ja_JP.UTF-8
export LANG=ja_JP.UTF-8
export LC_ALL=ja_JP.UTF-8
8. FAQ (Frequently Asked Questions)
Q1. I configured the locale correctly, but garbled text still appears.
A: Verify the locale settings again:
locale
If LANG=ja_JP.UTF-8 is not set, reconfigure using:
sudo update-locale LANG=ja_JP.UTF-8
sudo locale-gen ja_JP.UTF-8
sudo dpkg-reconfigure locales
Q2. Only certain files show garbled text.
A: Different files may have different character encodings. Check the encoding:
file -i sample.txt
If the file is not UTF-8, convert it:
iconv -f SHIFT_JIS -t UTF-8 sample.txt -o sample_utf8.txt
Or, using nkf:
nkf -w --overwrite sample.txt
Q3. I cannot input Japanese characters in the terminal.
A: Ensure that a Japanese input method (Fcitx or IBus) is installed.
sudo apt update
sudo apt install -y fcitx-mozc
im-config -n fcitx
Q4. Japanese text is garbled in WSL.
A: Set locale in WSL:
echo 'export LANG=ja_JP.UTF-8' >> ~/.bashrc
echo 'export LC_ALL=ja_JP.UTF-8' >> ~/.bashrc
source ~/.bashrc
Q5. Japanese text is garbled inside a Docker container.
A: If the locale is C.UTF-8, Japanese text will not display properly.
apt update && apt install -y locales
locale-gen ja_JP.UTF-8
export LANG=ja_JP.UTF-8
export LC_ALL=ja_JP.UTF-8
Q6. GUI menus and dialogs show corrupted Japanese text.
A: Install fonts and change font settings:
sudo apt install -y fonts-noto-cjk fonts-ipafont
9. Summary
This article provided a detailed explanation of the causes and solutions for garbled text issues in Ubuntu. Garbled characters typically occur due to misconfigured locale settings, missing fonts, mismatched character encoding, or incorrect terminal/editor configurations. However, with proper adjustments, these problems can be resolved effectively.
1. Main Causes of Garbled Text
- Incorrect locale configuration: If the system locale is set to
CorPOSIX, Japanese text cannot be displayed correctly - Fonts not installed: Without Japanese fonts, GUI applications and terminals cannot properly render Japanese characters
- Encoding mismatch: Opening files saved in different encodings (e.g., Shift_JIS) can cause corruption
- Improper terminal/editor settings: If encoding is not set to UTF-8, Japanese text may not display correctly
2. Solutions to Prevent Garbled Text
| Item | Solution |
|---|---|
| Locale configuration | Check with locale and run update-locale LANG=ja_JP.UTF-8 |
| Font installation | sudo apt install -y fonts-noto-cjk fonts-ipafont |
| Check file encoding | Use file -i or nkf --guess |
| Convert encoding | iconv -f SHIFT_JIS -t UTF-8 filename -o newfile |
| Terminal configuration | Set LESSCHARSET=utf-8 and change fonts to Noto Sans Mono CJK JP |
| Fix GUI garbled text | Set fonts to Noto Sans CJK JP and use gnome-tweaks if needed |
| Fix WSL garbled text | Set ja_JP.UTF-8 and configure fonts |
| Fix Docker garbled text | Run locale-gen ja_JP.UTF-8 and configure locale in Dockerfile |
3. Additional Recommendations
- Keep your system updated: Outdated packages may cause issues in the Japanese environment
sudo apt update && sudo apt upgrade -y
- Persist settings: Add locale settings to
~/.bashrcor~/.profileto apply them automatically on login - Back up configuration files: Before editing files like
/etc/default/locale, make a backup
Conclusion
The garbled text problem in Ubuntu can be resolved by properly configuring the four key components: locale, fonts, character encoding, and terminal/editor settings. By following the methods introduced in this guide, you can eliminate almost all garbled text issues across Ubuntu environments, whether in terminal sessions, GUI applications, WSL, or Docker containers.