LoginSignup
7
4

More than 1 year has passed since last update.

CentOS 8を日本語化する(ロケール、タイムゾーン、言語パック)

Last updated at Posted at 2021-05-15

What's?

タイトルどおり。CentOS 8を日本語化したいな、と。

環境

環境は、こちらです。

$ cat /etc/redhat-release
CentOS Linux release 8.3.2011

現在のロケールおよびタイムゾーンは、こちら。

$ localectl
   System Locale: LANG=en_US.UTF-8
       VC Keymap: us
      X11 Layout: us


$ timedatectl
               Local time: Sat 2021-05-15 11:54:17 UTC
           Universal time: Sat 2021-05-15 11:54:17 UTC
                 RTC time: Sat 2021-05-15 11:54:17
                Time zone: UTC (UTC, +0000)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: yes

Warning: The system is configured to read the RTC time in the local time zone.
         This mode cannot be fully supported. It will create various problems
         with time zone changes and daylight saving time adjustments. The RTC
         time is never updated, it relies on external facilities to maintain it.
         If at all possible, use RTC in UTC by calling
         'timedatectl set-local-rtc 0'.

これを日本語環境にしていきましょう。

ロケールを日本語にする

以下のコマンドで変更。

$ sudo localectl set-locale LANG=ja_JP.utf8

以下のように失敗する場合は

$ sudo localectl set-locale LANG=ja_JP.utf8
Failed to issue method call: Locale ja_JP.utf8 not installed, refusing.

先にglibc-langpack-jaをインストールしてから実行。

$ sudo dnf install glibc-langpack-ja

確認。

$ localectl 
   System Locale: LANG=ja_JP.utf8
       VC Keymap: us
      X11 Layout: us


$ cat /etc/locale.conf
LANG=ja_JP.utf8

キーマップの設定も変えておきましょう。日本語系のキーマップを確認。

$ localectl list-keymaps | grep jp
jp
jp-OADG109A
jp-dvorak
jp-kana86
jp106

今回は、jp106にしておきます。

$ sudo localectl set-keymap jp106

確認。

$ localectl
   System Locale: LANG=ja_JP.utf8
       VC Keymap: jp
      X11 Layout: jp
       X11 Model: jp106
     X11 Options: terminate:ctrl_alt_bksp

タイムゾーンをAsia/Tokyoにする

タイムゾーンをAsia/Tokyoに変更しようと試みます。

$ sudo timedatectl set-timezone Asia/Tokyo
Failed to set time zone: Failed to update /etc/localtime

が、うまくいきません…。

調べてみると、SELinuxが障壁になっているようなので

$ getenforce
Enforcing

1度無効化。

$ sudo setenforce 0

確認。

$ getenforce
Permissive

今度は、うまくいくようになります。

$ sudo timedatectl set-timezone Asia/Tokyo

設定したら、SELinuxは再度有効化しておきましょう。

$ sudo setenforce 1

タイムゾーンがAsia/Tokyoになりました。

$ timedatectl
               Local time: Sat 2021-05-15 21:05:26 JST
           Universal time: Sat 2021-05-15 12:05:26 UTC
                 RTC time: Sat 2021-05-15 21:05:26
                Time zone: Asia/Tokyo (JST, +0900)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: yes

Warning: The system is configured to read the RTC time in the local time zone.
         This mode cannot be fully supported. It will create various problems
         with time zone changes and daylight saving time adjustments. The RTC
         time is never updated, it relies on external facilities to maintain it.
         If at all possible, use RTC in UTC by calling
         'timedatectl set-local-rtc 0'.

日本語言語パックのインストール

それでも表記が日本語になっていませんね。langpacks-jaをインストールします。

$ sudo dnf install langpacks-ja

これで、日本語で表示されるようになります。

まとめて

スクリプトにすると、こんな感じでしょうか。

#!/bin/bash

# locale & keymap
sudo localectl set-locale LANG=ja_JP.utf8
sudo localectl set-keymap jp106

# timezone
sudo setenforce 0
sudo timedatectl set-timezone Asia/Tokyo
sudo setenforce 1

# lang pack
sudo dnf install -y langpacks-ja
7
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4