Fixing a locale-archive breakage

1) The symptoms of the problem

If you are greeted with the following errors when trying to use perl:

user$ perl -e ''
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

Or when using yum:

user$ yum help >/dev/null
Failed to set locale, defaulting to C

Or using any GTK application:

user$ gedit
(process:24839): Gtk-WARNING **: Locale not supported by C library.
Using the fallback 'C' locale

Or having your scripts failing in strange and unexpected ways:

user$ ...
/etc/profile.d/lang.sh: line 19: warning: setlocale: LC_CTYPE: cannot change locale (fr_FR.UTF-8): No such file or directory
/etc/profile.d/lang.sh: line 20: warning: setlocale: LC_COLLATE: cannot change locale (fr_FR.UTF-8): No such file or directory
/etc/profile.d/lang.sh: line 23: warning: setlocale: LC_MESSAGES: cannot change locale (fr_FR.UTF-8): No such file or directory
/etc/profile.d/lang.sh: line 26: warning: setlocale: LC_NUMERIC: cannot change locale (fr_FR.UTF-8): No such file or directory
/etc/profile.d/lang.sh: line 29: warning: setlocale: LC_TIME: cannot change locale (fr_FR.UTF-8): No such file or directory

Then you have a locale problem.

2) The solution

Here’s the command to list all the locales available on your system:

user$ locale -a
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_COLLATE to default locale: No such file or directory
C
POSIX

C and POSIX are the two default locales, always supported when everything else is broken. Here, obviously, something is wrong. I’m experiencing a locale-archive breakage. The file /usr/lib/locale/locale-archive is used by the apps to know which locales are supported on your system. If this database is broken, then you’ll have lots of warnings in all your programs, and they’ll always fallback to the C/POSIX locale (english, and plain us-ascii). To rebuild this database under Fedora, just issue the following command as root:

root# /usr/sbin/build-locale-archive

If you get an error when running the above command, see below. When the command is completed, you can check if it worked, issuing a locale -a at the prompt, you should now have a fairly complete list, way more than C and POSIX alone.

3) If it still doesn’t work

If the build-locale-archive command failed:

root# build-locale-archive
build-locale-archive: cannot open locale archive template file "/usr/lib/locale/locale-archive.tmpl": No such file or directory

Then you can try to just create this file with no data in it, it works for not too-recent Fedora versions. Then, try to rebuild the database:

root# touch /usr/lib/locale/locale-archive.tmpl
root# build-locale-archive

If you get another error:

root# build-locale-archive
build-locale-archive: cannot read archive header

Then you’re using a recent Fedora version, and you can no longer rebuild the locale-archive yourself. The packagers decided to truncate the /usr/lib/locale/locale-archive.tmpl file after build (to save disk space). In older versions, the archive could be rebuilt anyway, but this is no longer the case. Don’t panic, you only need to reinstall the glibc-common rpm (this is pretty painless), your locale-archive will be rebuilt in the process:

root# yum reinstall glibc-common

Leave a Reply

7 Comments on "Fixing a locale-archive breakage"

Notify of
avatar
Sort by:   newest | oldest | most voted
Federico
Guest
Michael Hartman
Guest

Thanks, this post helped me a lot! I was having this problem after clean install of Fedora 23 while keeping my old home partition (which lives with me from Fedora 17 or something like that). Issuing command dnf reinstall glibc-common solved my problem. I run it from xterm as I was not able to launch gnome-terminal with broken locale.

trackback

[…] Кстати, вот хорошая инструкция для Red Hat/Fedora Core: Fixing a locale-archive breakage (что делать когда поломалось совсем все). В моем случае […]

jobst
Guest

Some random stuff that one may find useful..

Yes, indeed, thank you!

Laurent
Guest

Hi, thks for this blog …

I read and apply your process, but i always the problem.

When i make the command :

/usr/sbin > sudo build-locale-archive

I have this error :

build-locale-archive: cannot read archive header

I try to reinstall the glibc-common lib, but fedora 12 doesn’t find mirror to download the rpm, so i make a manualy download and when i install it, fedora said it’s already installed.

Have you an idea ?

Regards

wpDiscuz