iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🔠

WSL 2 Initial Setup: Basic Guide for Japanese Language Support in Debian

に公開

Introduction

In this article, I will explain how to localize Debian on WSL (Windows Subsystem for Linux) into Japanese for those who are using it for the first time on Windows.
By localizing Debian, command output results and error messages will be displayed in Japanese.

Glossary

  • WSL (Windows Subsystem for Linux):
    A compatibility layer for running Linux environments on Windows.

  • Debian:
    A Linux distribution with a solid reputation for stability and freedom.

  • Locale:
    Regional settings used by the system for language, dates, numerical values, etc.

  • Time Zone:
    Settings for adjusting system time according to the region.

  • task-japanese:
    A package in Debian for bulk-installing the Japanese environment.

  • sudo:
    A tool for executing commands with temporary administrative privileges.

  • locale.gen:
    A file describing the locale settings to be enabled.

  • dpkg-reconfigure:
    A standard Debian tool for reconfiguring packages.

  • tzdata:
    A package for managing time zone information.

  • PowerShell:
    A high-performance command-line shell standard in Windows.

  • man:
    A manual display command used in UNIX-like systems.

1. Reasons and Background for Setting up a Japanese Environment

1.1 Why Localization is Necessary

When using Debian on WSL 2, an English locale is set by default, and system messages and error messages are also displayed in English.
For beginners who are not accustomed to English, the English output may hinder understanding or interfere with tasks.

By localizing the environment, the output will be in Japanese, making it easier to understand.

1.2 Problems that Occur with the English Locale

Leaving the locale as English can lead to the following problems:

  • Command results and error contents are difficult to understand intuitively.
  • Japanese display becomes corrupted in some applications.
  • Japanese input and display settings do not function correctly.

To avoid these issues, it is important to set up the locale and time zone for a Japanese environment.

1.3 Benefits Gained from Localization

The main benefits of setting up a Japanese environment are as follows:

  • Japanese system messages make it easier to identify the cause of errors and take action.
  • Japanese manuals and documentation are displayed, leading to a deeper understanding.
  • Troubles with Japanese input and display can be prevented in advance.

Especially for users unfamiliar with Linux, output in their native language provides a sense of security and acts as a factor in lowering the learning cost.

2. Preparation and Flow for Localization

2.1 Steps for Localization Tasks

The work to localize Debian into Japanese is roughly divided into the following 4 steps.

  1. Installing Japanese packages
  2. Configuring the locale (language settings)
  3. Setting the time zone
  4. Applying settings and verifying operation

By proceeding in this order, you can make your WSL environment support Japanese.

[Figure 1] Overall flow of Japanese environment construction

2.2 Launching and Closing Windows Terminal

Debian on WSL 2 is operated via Windows Terminal.
Here, we introduce how to launch and close Windows Terminal.

Launching Windows Terminal

Follow these steps to launch Windows Terminal.

  1. Execute the command wt:
    Press [Win]+R to open the [Run] window, type wt, and press [Enter].
    Run
    [Image 01] Entering wt in the Run window

  2. Launching the terminal:
    Windows Terminal will launch.
    Windows Terminal
    [Image 02] Windows Terminal launch screen

Closing Windows Terminal

Follow these steps to close Windows Terminal.

  1. Enter the closing key:
    With Windows Terminal active, press [Alt]+[F4].
    Windows Terminal
    [Image 03] Windows Terminal window before Alt+F4 operation

  2. Confirming tab closure:
    If multiple tabs are open, a confirmation dialog "Do you want to close all tabs?" will be displayed.
    Select [Close all] to close all tabs.
    Windows Terminal
    [Image 04] Confirmation dialog to close all tabs with Alt+F4

  3. Closing the terminal:
    The terminal will close.

2.3 Launching and Closing Debian

Debian on WSL 2 can be launched and closed from the Windows Terminal.
Here, we introduce the basic operations.

Launching Debian

Follow these steps to launch Debian.

  1. Selecting Debian:
    Press [Ctrl]+[Shift]+[Space] to open the dropdown list and select [Debian].
    Dropdown Menu
    [Image 05] Selecting Debian from the dropdown

  2. Launching Debian:
    Debian will launch.
    Debian - Terminal
    [Image 06] State where the Debian shell has launched

Closing Debian

Follow these steps to close Debian.

  1. Entering the exit command:
    On the Debian command line, type exit and press the [Enter] key.
    Debian exit - Terminal
    [Image 07] Closing Debian with the exit command

  2. Closing Debian:
    Debian will close and return to the original powershell.
    Windows Terminal
    [Image 08] State after closing Debian and returning to PowerShell

2.4 How to Use the sudo Command

Overview of sudo

In Debian, certain operations such as installing packages or changing configuration files require administrative (root) privileges.
To perform these operations as a regular user, use the sudo (Superuser Do) command.

By using sudo, you can temporarily obtain administrative privileges to perform the necessary operations.

Practical Examples of Using sudo

For example, to update the package list, enter the following:

sudo apt update

If you execute the command without sudo, an error will occur as follows:

E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/

When you include sudo, the command is executed with administrative privileges, so no error occurs.

Regarding Password Entry when Executing sudo

When using sudo, you will be prompted to enter a password as follows:

[sudo] password for <username>:

In this case, enter the login user's password that you set when you installed Debian.

3. Installing Japanese Packages

To localize Debian into Japanese, you need to install Japanese-related packages.
Here, we introduce a method using the task-japanese meta-package.

3.1 Overview of the task-japanese Package

The task-* packages are meta-packages that group multiple packages needed for a specific purpose.
task-japanese is a meta-package for localizing Debian into Japanese, containing Japanese locale files, Japanese fonts, etc.

Japanese messages and manuals will also be displayed in the CLI environment (terminal).

3.2 Installation Steps for task-japanese

Follow these steps to install the task-japanese package.

  1. Updating the package list:

    sudo apt update
    
  2. Installing task-japanese:

    sudo apt install task-japanese
    
  3. Installation results:
    During installation, messages like the following will be output.

    Reading package lists... Done
    Building dependency tree... Done
     .
     .
     .
    Setting up xfonts-unifont (1:15.0.01-2) ...
    Processing triggers for libc-bin (2.36-9+deb12u10) ...
    

After installation, Japanese locales and fonts will be available.
However, additional configuration is required for display, and Debian must be restarted.

4. Locale Settings

After installing the Japanese packages, you need to configure the locale (regional and language settings) so that the system operates in Japanese. Here, we introduce the basics of locales and how to set them up interactively and via the command line.

4.1 Overview of Locales

A locale is a setting that determines in which language and format (character encoding, date, numbers, etc.) the system displays information. For example, en_US.UTF-8 represents American English, and ja_JP.UTF-8 represents the Japanese environment.

In the initial state of Debian, it is often set to en_US.UTF-8. To localize it, you need to enable ja_JP.UTF-8 and set it as the default locale.

4.2 Locale Configuration Flow

The locale is set according to the flow shown below. There are two types of settings: interactive and CLI (command line).

[Figure 2] Locale configuration flow (Interactive vs CLI)

4.3 Interactive Configuration Method

You can set the locale interactively using the following command.

sudo /usr/sbin/dpkg-reconfigure locales
  1. Selecting locales to use (Use the space key to select/deselect)
    Check the Japanese locale (ja_JP.UTF-8).
    Configure Locales
    [Image 09] Checking ja_JP.UTF-8 on the locale selection screen

  2. Selecting the default locale
    Select ja_JP.UTF-8 as the default.
    default locale
    [Image 10] Selecting ja_JP.UTF-8 as the default locale

  3. Creating the locale
    The selected locale will be created.

    Generating locales (this might take a while)...
    en_US.UTF-8... done
    ja_JP.UTF-8... done
    Generation complete.
    

This completes the locale settings.
After restarting Debian, output such as error messages will be in Japanese.

4.4 Configuration via CLI (Command Line)

You can also set the locale from the command line. Follow these steps to configure the locale.

# Add Japanese locale
# - Uncomment ja_JP.UTF-8
# Note that there may be spaces before the comment out on some lines
sudo sed -i 's/# ja_JP.UTF-8/ja_JP.UTF-8/ig' /etc/locale.gen

# Re-generate locales
sudo /usr/sbin/locale-gen

# Set default locale
sudo /usr/sbin/update-locale LANG=ja_JP.UTF-8

With this setting, the Japanese locale will be enabled, and Japanese output will be active after a restart.

5. Time Zone Settings

Following the locale settings, setting the system time zone to Japan Standard Time (Asia/Tokyo) ensures that the date display and timestamps in logs are shown correctly.
Here, we introduce the setting methods for both interactive and CLI (command line) modes.

5.1 Overview of Time Zones

In Linux systems, setting the time zone allows the output of the date command and timestamps in log files to be displayed accurately.
In the initial state of WSL, it may be set to UTC (Coordinated Universal Time), which has a 9-hour difference from Japan time, so it is common to change it to Asia/Tokyo.

5.2 Time Zone Configuration Flow

The time zone is set according to the flow shown below. There are two types of settings: interactive and CLI (command line).

[Figure 3] Time zone configuration flow (Interactive vs CLI)

5.3 Interactive Configuration Method

You can set the time zone interactively using the following command.

sudo /usr/sbin/dpkg-reconfigure tzdata
  1. Selecting the region:
    Select Asia.
    TimeZone Settings
    [Image 11] Time Zone Region: Asia selection screen

  2. Selecting the city:
    Select Tokyo.
    TimeZone Settings
    [Image 12] Time Zone City: Tokyo selection screen

  3. Time zone configuration:
    A message like the following will be output.

    Current default time zone: 'Asia/Tokyo'
    Local time is now:      Wed Mar 26 19:16:57 JST 2025.
    Universal Time is now:  Wed Mar 26 10:16:57 UTC 2025.
    

5.4 Configuration via CLI (Command Line)

To set the time zone from the CLI, follow these steps.

# Set /etc/localtime to Asia/Tokyo
sudo ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

# Reconfigure time zone data
# - Since localtime is already set, no interaction is required
sudo /usr/sbin/dpkg-reconfigure -f noninteractive tzdata

If a message like the following is output, the time zone has been set correctly.

Current default time zone: 'Asia/Tokyo'
Local time is now:      Wed Mar 26 19:43:51 JST 2025.
Universal Time is now:  Wed Mar 26 10:43:51 UTC 2025.

6. Reflecting Settings and Verifying Operation

After completing the locale and time zone settings, verify that the changes have been correctly reflected in the system. This chapter introduces how to restart WSL and how to use basic verification commands.

[Figure 4] Flow of reflection and verification steps

6.1 Restarting WSL

WSL settings may not be applied simply by restarting the terminal.
Follow these steps to completely restart WSL.

  1. Launch PowerShell:
    Launch PowerShell (or Command Prompt).

  2. Execute shutdown:
    Run the following command.

    wsl --shutdown
    
  3. Launch Debian:
    Launch Debian from Windows Terminal.

6.2 How to Verify Locale and Time Zone

To verify whether the locale and time zone settings have been correctly reflected, execute the following commands.

Verifying the Locale

You can check the current locale settings with the locale command.

locale

Output example:

LANG=ja_JP.UTF-8
LANGUAGE=
LC_CTYPE="ja_JP.UTF-8"
LC_NUMERIC="ja_JP.UTF-8"
LC_TIME="ja_JP.UTF-8"
LC_COLLATE="ja_JP.UTF-8"
LC_MONETARY="ja_JP.UTF-8"
LC_MESSAGES="ja_JP.UTF-8"
LC_PAPER="ja_JP.UTF-8"
LC_NAME="ja_JP.UTF-8"
LC_ADDRESS="ja_JP.UTF-8"
LC_TELEPHONE="ja_JP.UTF-8"
LC_MEASUREMENT="ja_JP.UTF-8"
LC_IDENTIFICATION="ja_JP.UTF-8"
LC_ALL=

As shown above, if each setting item is ja_JP.UTF-8, the Japanese locale is enabled.

Verifying the Time Zone

You can check the time and time zone with the date command.

date

Output example:

2025年  3月 26日 水曜日 20:39:15 JST

As shown above, if JST (Japan Standard Time) is displayed, the time zone is set correctly.

7. Troubleshooting

7.1 Locale and Time Configuration Troubles

[SYS-001] Locale settings are not reflected

  • Symptoms: English settings remain, such as LANG=C.
  • Cause: Locale generation or configuration files are not set.
  • Actions:
    1. Execute locale|grep LANG to check if it is set to LANG=ja_JP.UTF-8.
    2. Execute sudo /usr/sbin/dpkg-reconfigure locales and set ja_JP.UTF-8 as the default locale.
    3. Restart with wsl --shutdown to apply the changes.

[SYS-002] Time zone is not Japan time

  • Symptoms: UTC or other time zones are displayed by the date command.
  • Cause: The time zone remains in its initial state (such as UTC).
  • Actions:
    1. Execute sudo dpkg-reconfigure tzdata.
    2. Select 'Asia' → 'Tokyo'.
    3. Verify the JST display with the date command.

7.2 Japanese Display Troubles

[DISP-001] Japanese fonts are not displayed and characters are garbled

  • Symptoms: Japanese is displayed as "□" or "?".
  • Cause: Japanese fonts are not installed or the cache is not updated.
  • Actions:
    1. Install Japanese fonts (execute sudo apt install fonts-noto-cjk).
    2. Installing fonts other than noto (VL Gothic: fonts-vlgothic, Takao fonts: fonts-takao) is also acceptable.
    3. Regenerate the font cache (execute fc-cache -fv).

[DISP-002] man pages or command messages remain in English

  • Symptoms: man ls and other commands are displayed in English.
  • Cause: Japanese manuals or translation files have not been introduced.
  • Actions:
    1. Install Japanese man pages (execute sudo apt install manpages-ja manpages-ja-dev).
    2. Note that some man pages are not translated, so complete localization is difficult.

Conclusion

By setting up the Japanese environment for Debian on WSL 2, interacting with the system has become much easier to understand.
Since messages and manuals are in Japanese, comprehension is straightforward.

By following the steps introduced in this guide, you can localize Debian without any problems.
We have also covered representative troubles, so you can handle issues if they arise.

Going forward, let's build your own development environment by customizing WSL and configuring bash.

Happy Hacking!

References

Websites

GitHubで編集を提案

Discussion