Fixing a locale-archive breakage
Post
Cancel

Fixing a locale-archive breakage

The symptoms of the problem

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

1
2
3
4
5
6
7
8
$ perl -e 1
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:

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

Or using any GTK application:

1
2
3
4
$ 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:

1
2
3
4
5
6
...
/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.

The solution

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

1
2
3
4
5
6
$ 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:

1
# /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.

If it still doesn’t work

If the build-locale-archive command failed:

1
2
# 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:

1
2
# touch /usr/lib/locale/locale-archive.tmpl
build-locale-archive

If you get another error:

1
2
# 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:

1
# yum reinstall glibc-common
This post is licensed under CC BY 4.0 by the author.