2023年1月7日星期六

[solved]Amazon Linux 2 encounter 'warning: setlocale: LC_CTYPE: cannot change locale (en_US.UTF-8): No such file or directory' after 'yum update'

Little trick to fix the  'warning: setlocale: LC_CTYPE: cannot change locale (en_US.UTF-8): No such file or directory' issue on amazon linux 2 after yum update.


Thanks to this post:  thought it is japanese, but the solving trick is the same.

https://nyan.blog/2021/10/11/ec2amazon-linux-2%E3%81%A7%E3%80%8Cyum-update%E3%80%8D%E3%81%97%E3%81%9F%E3%82%89%E3%80%8Cfailed-to-set-locale-defaulting-to-c%E3%80%8D%E3%81%8C%E8%A1%A8%E7%A4%BA%E3%81%95%E3%82%8C%E3%82%8B/


[Description]

After yum update,  CLI prompted with following message ,

```

-bash: warning: setlocale: LC_CTYPE: cannot change locale (en_US.UTF-8): No such file or directory

-bash: warning: setlocale: LC_COLLATE: cannot change locale (en_US.UTF-8): No such file or directory

-bash: warning: setlocale: LC_MESSAGES: cannot change locale (en_US.UTF-8): No such file or directory

-bash: warning: setlocale: LC_NUMERIC: cannot change locale (en_US.UTF-8): No such file or directory

-bash: warning: setlocale: LC_TIME: cannot change locale (en_US.UTF-8): No such file or directory

```

and   export LC_ALL="en_US.UTF-8" won't work.

-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)

-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)


$ ll /usr/lib/locale/  and you will only find C.utf8

  C.utf8

  locale-archive.tmpl


$ 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=en_US.UTF-8

LC_CTYPE="en_US.UTF-8"

LC_NUMERIC="en_US.UTF-8"

LC_TIME="en_US.UTF-8"

LC_COLLATE="en_US.UTF-8"

LC_MONETARY="en_US.UTF-8"

LC_MESSAGES="en_US.UTF-8"

LC_PAPER="en_US.UTF-8"

LC_NAME="en_US.UTF-8"

LC_ADDRESS="en_US.UTF-8"

LC_TELEPHONE="en_US.UTF-8"

LC_MEASUREMENT="en_US.UTF-8"

LC_IDENTIFICATION="en_US.UTF-8"

LC_ALL=en_US.UTF-8



[How to solve it]  

If you are using en_US.UTF-8, following will do:

$sudo localedef -f UTF-8 -i en_US en_US.UTF-8