How to Configure Locale on Ubuntu: Complete Guide to Japanese UTF-8, Troubleshooting, Docker & WSL

1. Introduction

In Linux environments such as Ubuntu, locale configuration plays a critically important role. A locale defines how the system and applications handle language display, date and time formats, currency symbols, decimal points, commas, and other region-specific conventions, allowing the environment to be optimized for different countries and cultures.

For example, immediately after installing Ubuntu, the system is often configured in English by default. As a result, system messages, application interfaces, and even date and number formats may feel unfamiliar to Japanese users. To change these settings to Japanese and align them with Japanese conventions, proper locale configuration is essential.

Not only for server use, but also when using Ubuntu Desktop daily, or in virtualized environments such as WSL (Windows Subsystem for Linux) and Docker, correctly configuring locales enables full Japanese support, prevents character encoding issues, and provides a more comfortable user experience.

This article provides a systematic explanation of the role of locales in Ubuntu, how to configure them, and how to resolve common issues. Whether you are new to Ubuntu or need to adjust locale settings in an existing environment, this guide will serve as a reliable reference.

2. Checking the Current Locale Configuration

Before modifying locale settings on Ubuntu, it is important to understand the current configuration. This section explains how to check the active locale settings using available commands.

The most basic way to check locale settings is to run the locale command in the terminal. This displays a detailed list of the currently active locale settings. Common output includes entries such as the following:

LANG=ja_JP.UTF-8
LC_CTYPE="ja_JP.UTF-8"
LC_NUMERIC="ja_JP.UTF-8"
LC_TIME="ja_JP.UTF-8"
...

LANG represents the system-wide default locale, while each LC_ variable controls a specific category such as character classification, numeric formatting, date and time, or messages. If ja_JP.UTF-8 is displayed for LANG or LC_MESSAGES, the Japanese locale is active.

To check which locales are available on the system, use the following command:

locale -a

This command lists all installed locales. Confirm that Japanese-related locales such as ja_JP.UTF-8 are included.

If Japanese locales are missing or the output of locale shows unexpected values, you will need to add or reconfigure locales using the steps described below.

3. When the Japanese Locale Is Not Available

If locale -a does not include ja_JP.UTF-8, or if Japanese text is not displayed correctly, you must install and enable the Japanese locale. The procedure is explained in detail below.

To generate and use Japanese locales, packages such as language-pack-ja and locales are required. Without these packages, Japanese locale support cannot be enabled.

Installing Required Packages

Run the following commands in the terminal to install Japanese language support:

sudo apt update
sudo apt install language-pack-ja

Depending on your Ubuntu version or use case, it is also recommended to install the locales package:

sudo apt install locales

Generating the Japanese Locale

After installing the required packages, generate the Japanese locale with the following command:

sudo locale-gen ja_JP.UTF-8

Once completed, ja_JP.UTF-8 will appear in the output of locale -a.

Applying the Locale

To ensure the locale is applied, set the default system locale using update-locale:

sudo update-locale LANG=ja_JP.UTF-8

This ensures that newly opened terminals and login sessions use the Japanese locale.

4. Generating and Enabling Locales

After making Japanese locales available, the next step is to generate and apply them system-wide. This section explains how to ensure the configuration is correctly reflected.

Locale Generation

In most cases, running sudo locale-gen ja_JP.UTF-8 is sufficient. However, in some situations you may need to manually edit /etc/locale.gen.

  1. Open /etc/locale.gen with a text editor such as nano.
sudo nano /etc/locale.gen
  1. If the line ja_JP.UTF-8 UTF-8 exists but is commented out with #, remove the #.
  2. Save the file and exit the editor.
  3. Generate locale data.
sudo locale-gen

Enabling the Locale

Use update-locale to set Japanese as the default locale:

sudo update-locale LANG=ja_JP.UTF-8

This updates /etc/default/locale automatically.

If you want to specify multiple locale categories individually, you can do so as follows:

sudo update-locale LANG=ja_JP.UTF-8 LC_TIME=ja_JP.UTF-8 LC_MESSAGES=ja_JP.UTF-8

When Settings Take Effect

Locale changes may not apply immediately. If necessary, log out and log back in, or reboot the system to activate the new settings.

5. System-Wide vs Per-User Locale Settings

Ubuntu supports two types of locale configuration: system-wide and per-user. Choosing the appropriate approach allows for flexible environment management.

System-Wide Locale Configuration

System-wide settings are managed via /etc/default/locale or the update-locale command. These settings apply to all users who log in to the system.

sudo update-locale LANG=ja_JP.UTF-8

This sets Japanese as the default language for all users.

Per-User Locale Configuration

To configure locales for a specific user only, edit files in the user’s home directory, such as ~/.pam_environment.

  1. Log in as the target user and open the file.
nano ~/.pam_environment
  1. Add the following line:
LANG=ja_JP.UTF-8

You may also define additional LC_* variables as needed.

Using the localectl Command

On systemd-based systems, locales can also be configured using localectl:

sudo localectl set-locale LANG=ja_JP.UTF-8

6. Configuring Locales via GUI (Ubuntu Desktop / GNOME)

On Ubuntu Desktop, locale settings can be configured easily through the graphical interface.

Changing Locale via Settings

  1. Open “Settings” from the system menu.
  2. Select “Region & Language”.
  3. Choose “Japanese” under Language.
  4. Set “Formats” to Japan or Japanese to adjust date, time, and currency formats.
  5. Restart or log out and log back in when prompted.

Configuring Input Methods (IME)

For comfortable Japanese input, configure an input method such as Fcitx5 or IBus with engines like Mozc.

  • Add “Japanese (Mozc)” from Input Sources
  • Switch input methods using shortcuts such as Super + Space

Troubleshooting Display Issues

  • Ensure Japanese font packages such as fonts-noto-cjk are installed
  • Check application-specific language settings
  • Restart the system or log out to apply changes

7. Verification and Troubleshooting

After configuring locales, verify that the settings are correctly applied and address any issues.

Confirming Locale Settings

locale

If ja_JP.UTF-8 is shown for LANG and LC_*, the configuration is successful.

Checking Date and Number Formats

date

Common Issues and Solutions

1. Garbled Characters

  • Install Japanese fonts such as fonts-noto-cjk.

2. Settings Not Applied

  • Log out or reboot.
  • Reload settings using source /etc/default/locale.

3. Mixed Languages

  • Unify settings using sudo update-locale LC_ALL=ja_JP.UTF-8.

8. Locale Configuration in Docker and WSL

Ubuntu is frequently used in Docker containers and WSL environments. Locale configuration remains important but requires additional steps.

Docker

FROM ubuntu:24.04

RUN apt-get update && \
    apt-get install -y language-pack-ja locales && \
    locale-gen ja_JP.UTF-8 && \
    update-locale LANG=ja_JP.UTF-8

ENV LANG=ja_JP.UTF-8
ENV LANGUAGE=ja_JP:ja
ENV LC_ALL=ja_JP.UTF-8

WSL

sudo apt update
sudo apt install language-pack-ja locales
sudo locale-gen ja_JP.UTF-8
sudo update-locale LANG=ja_JP.UTF-8
export LANG=ja_JP.UTF-8
export LANGUAGE=ja_JP:ja
export LC_ALL=ja_JP.UTF-8

9. FAQ

Q1. ja_JP.UTF-8 does not appear in locale -a.
A. Install required packages and generate the locale.

Q2. Locale changes are not applied.
A. Log out, reboot, and verify environment variable settings.

Q3. Japanese text appears garbled.
A. Install Japanese fonts and configure terminal fonts.

Q4. Which locale setting has priority?
A. Priority order is LC_ALL > LC_* > LANG.

Q5. Can the same steps be used in Docker and WSL?
A. The basics are the same, but Dockerfiles and Windows font settings require attention.

10. Conclusion

This article covered everything from the fundamentals of locale configuration in Ubuntu to detailed Japanese UTF-8 setup, troubleshooting, and special cases such as Docker and WSL environments.

Locales affect not only language display but also date formats, currency, numeric representation, and character encoding. Proper configuration significantly improves usability and stability.

By combining command-line configuration, GUI-based settings, and per-user customization, you can build a flexible and comfortable Ubuntu environment.

This guide aims to serve as a reliable resource for anyone setting up a Japanese Ubuntu environment.

年収訴求