'How to fix 'character map file `UTF-8' not found'

I'm setting up a UBI rhel8 container. I need to execute this command:

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

which failed with:

character map file `UTF-8' not found: No such file or directory
cannot read character map directory `/usr/share/i18n/charmaps': No such file or directory


Solution 1:[1]

You need to install these packages

yum -y install glibc-locale-source glibc-langpack-en

and then re-run localedef command

Solution 2:[2]

On Debian/Ubuntu, I was able to solve this via apt install locales.

Solution 3:[3]

I ran into this same symptom (locale-gen can't find charmap files) after upgrading from Ubuntu 20.04 to 22.04 in WSL 1. The problem is that there is a bug in WSL 1 that prevents gunzip from running. This is a problem for locale-gen because, at least in Ubuntu 22.04, the charmap files in /usr/share/i18n/charmaps are stored in GZip *.gz format. Apparently, locale-gen depends on gunzip to unzip the charmap files, and when it can't run it, it is stuck.

The solution was

  1. copy UTF-8.gz to the Windows filesystem
  2. unzip it to UTF-8 with a Windows tool (such as 7-zip)
  3. copy UTF-8 back to /usr/share/i18n/charmaps

Then locale-gen worked correctly.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mina Alber
Solution 2 Tobias J
Solution 3 Josh