I have a need to reduce the size of the locale-archive file on some of my RHEL6 systems.

Here is that file on my system:

[root@-dev-007 locale]# ls -l
total 96800
-rw-r--r--. 1 root root 99158704 Sep  9 15:22 locale-archive
-rw-r--r--. 1 root root        0 Jun 20  2012 locale-archive.tmpl

So I did this ...

[root@-dev-007 locale]# localedef --list | grep zh_CN
zh_CN
zh_CN.gb18030
zh_CN.gb2312
zh_CN.gbk
zh_CN.utf8

... so I figured I could get rid of zh_CN like so ...

[root@-dev-007 locale]# localedef --delete-from-archive zh_CN

... and I can see zh_CN does not get listed anymore like so ...

[root@-dev-007 locale]# localedef --list | grep zh_CN
zh_CN.gb18030
zh_CN.gb2312
zh_CN.gbk
zh_CN.utf8

... but the size of the locale-archive does not get smaller ...

[root@-dev-007 locale]# ls -l  
total 96800
-rw-r--r--. 1 root root 99158704 Sep  9 17:16 locale-archive
-rw-r--r--. 1 root root        0 Jun 20  2012 locale-archive.tmpl

... is there something else I need to do?

up vote 18 down vote accepted

You can first remove all unneeded locales by doing:

$localedef --list-archive | grep -v -i ^en | xargs localedef --delete-from-archive

Where ^en can be replaced by the locale you wish to keep

Then

$build-locale-archive

If this gives you an error similar to

$build-locale-archive
/usr/sbin/build-locale-archive: cannot read archive header

Then try this

$mv /usr/lib/locale/locale-archive /usr/lib/locale/locale-archive.tmpl
$build-locale-archive

If that still fails, check your version. According to this page newer versions don't have the necessary files to rebuild the archive in order to save space. You'll need to run

yum reinstall glibc-common

In later releases of Red Hat Enterprise Linux, you may use dnf, a similar application.

  • 3
    I noticed though that I loss my ssh connection to the host when I execute build-locale-archive ... any way of preventing this? – Red Cricket Sep 10 '13 at 22:23
  • 2
    I'd be careful attempting this. Broke my CentOS server and took me 30 mins to figure out a solution. unix.stackexchange.com/questions/246705/… – PJ Brunet Dec 1 '15 at 23:02
  • dnf in rhel??? Surely you mean yum ;-) – Dani_l May 7 '16 at 13:53

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.