0
2

More than 3 years have passed since last update.

USキーボードでAWS (EC2) を使う。manpath: can't set the locale; の解決策。

Last updated at Posted at 2021-02-27

問題

EC2でログインすると、以下のエラーが表示される。
manpath: can't set the locale; make sure \$LC_* and $LANG are correct

(USキーボードを使用している記事があまり見当たらずに苦労したため、メモとして残しておきます。)

エラー内容

~ % ssh aws_key_rsa 
Last login: Sat Feb 27 17:21:44 2021 from kd059138042141.ppp-bb.dion.ne.jp

       __|  __|_  )
       _|  (     /   Amazon Linux 2 AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-2/
-bash: warning: setlocale: LC_CTYPE: cannot change locale (us_US.UTF-8): No such file or directory
-bash: warning: setlocale: LC_COLLATE: cannot change locale (us_US.UTF-8): No such file or directory
-bash: warning: setlocale: LC_MESSAGES: cannot change locale (us_US.UTF-8): No such file or directory
-bash: warning: setlocale: LC_NUMERIC: cannot change locale (us_US.UTF-8): No such file or directory
-bash: warning: setlocale: LC_TIME: cannot change locale (us_US.UTF-8): No such file or directory
manpath: can't set the locale; make sure $LC_* and $LANG are correct
[user@ip-address ~]$ 

エラーが起きた時の状況

インスタンス作成後は、以下のようにタイムゾーンにUTC(世界協定時刻)がデフォルト設定されていました。

$ timedatectl
               Local time: Sun 2019-08-25 10:27:53 UTC  ……①
           Universal time: Sun 2019-08-25 10:27:53 UTC
                 RTC time: Sun 2019-08-25 10:27:52
                Time zone: UTC (UTC, +0000)  ……②
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

私は、上の ①Local time と ②Time zone に変更を加えました。

$ timedatectl list-timezones | grep Asia/Tokyo
Asia/Tokyo
# 日本時間がタイムゾーンに設定可能かどうかを確認するコマンド。

$ sudo timedatectl set-timezone Asia/Tokyo
# Time zone を Asia/Tokyo に変更する。

その結果が、以下の ①’ と ②’ です。

[user@ip-address ~]$ timedatectl
      Local time: 日 2021-02-28 08:31:59 JST  ……①’
  Universal time: 土 2021-02-27 23:31:59 UTC
        RTC time: 土 2021-02-27 23:31:59
       Time zone: Asia/Tokyo (JST, +0900)  ……②’
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

このあたりで、ログイン時にエラーが出るようになりました。
※複数の設定を同時に変更していたため、デフォルトから上の状況だけを試した場合、再現性がない場合があります。

エラーが起こる時の環境変数


[user@ip-address ~]$ locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=us_US.UTF-8
LC_CTYPE="us_US.UTF-8"
LC_NUMERIC="us_US.UTF-8"
LC_TIME="us_US.UTF-8"
LC_COLLATE="us_US.UTF-8"
LC_MONETARY="us_US.UTF-8"
LC_MESSAGES="us_US.UTF-8"
LC_PAPER="us_US.UTF-8"
LC_NAME="us_US.UTF-8"
LC_ADDRESS="us_US.UTF-8"
LC_TELEPHONE="us_US.UTF-8"
LC_MEASUREMENT="us_US.UTF-8"
LC_IDENTIFICATION="us_US.UTF-8"
LC_ALL=

[user@ip-address ~]$ localectl
   System Locale: LANG=us_US.UTF-8   #この列を、以下で編集していきます。
       VC Keymap: us
      X11 Layout: us
       X11 Model: pc105+inet
     X11 Options: terminate:ctrl_alt_bksp

[user@ip-address ~]$ timedatectl
      Local time: 日 2021-02-28 08:19:29 JST  ……①’
  Universal time: 土 2021-02-27 23:19:29 UTC
        RTC time: 土 2021-02-27 23:19:29
       Time zone: Asia/Tokyo (JST, +0900)  ……②’
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

[user@ip-address ~]$ vim /etc/locale.conf
Lang=us_US.UTF-8 

解決策

①Terminal の設定を変える

Terminal > Preferences > Profiles > Advanced > Set locale environment variables on starup のチェックを外す。
Screen Shot 2021-02-28 at 8.11.26.png

②Language & Region の確認

Screen Shot 2021-02-27 at 19.29.30.png
Region が Japan に、そして Preffered languages のトップが English にしています。

③ $LANG の変更

vim /etc/locale.conf
Lang=ja_JP.utf8

④System Locale を変更する

[user@ip-address ~]$ sudo localectl set-locale LANG=ja_JP.utf8
[user@ip-address ~]$ localectl
   System Locale: LANG=ja_JP.utf8  #先ほどの LANG=us_US.UTF-8 から変わりました。
       VC Keymap: us
      X11 Layout: us
       X11 Model: pc105+inet
     X11 Options: terminate:ctrl_alt_bksp
[user@ip-address ~]$ vi /etc/locale.conf

⑤rebootして、再度ログインする。

$ sudo reboot
Connection to {IPアドレス} closed by remote host.
Connection to {IPアドレス} closed.
% ssh aws_key_rsa 
Last login: (略)

       __|  __|_  )
       _|  (     /   Amazon Linux 2 AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-2/
[user@ip-address ~]$ 

これでエラーがなく、EC2にログインできました。

補足①

[user@ip-address ~]$ locale
LANG=ja_JP.utf8
LC_CTYPE="ja_JP.utf8"
LC_NUMERIC="ja_JP.utf8"
LC_TIME="ja_JP.utf8"
LC_COLLATE="ja_JP.utf8"
LC_MONETARY="ja_JP.utf8"
LC_MESSAGES="ja_JP.utf8"
LC_PAPER="ja_JP.utf8"
LC_NAME="ja_JP.utf8"
LC_ADDRESS="ja_JP.utf8"
LC_TELEPHONE="ja_JP.utf8"
LC_MEASUREMENT="ja_JP.utf8"
LC_IDENTIFICATION="ja_JP.utf8"
LC_ALL=

LC_*が自動で切り替わっていることが確認できました。

補足② (当時の私の .bash_profile の状況です。)

[user@ip-address ~]$vim .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

環境変数についての投稿のため、補足しておきます。

0
2
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
0
2