In my bare centos6.5 system, which is a docker container, en_US.utf-8 locale is missing:

bash-4.1# locale -a

Normally in Ubuntu there is command locale-gen to do this:

# locale-gen en_US.UTF-8
# echo 'LANG="en_US.UTF-8"' > /etc/default/locale

How can I do this in centos 6.5?


locale-gen is not present in Centos/Fedora.

You must use localedef:

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

From man localedef:

       localedef - define locale environment

       localedef [-c][-f charmap][-i sourcefile][-u code_set_name] name

       The localedef utility shall convert source definitions for locale cate‐
       gories into a format usable by the functions and utilities whose opera‐
       tional behavior is determined by the setting of the locale  environment
       variables    defined    in    the    Base    Definitions    volume   of
       IEEE Std 1003.1-2001, Chapter 7, Locale. It  is  implementation-defined
       whether users have the capability to create new locales, in addition to
       those  supplied  by  the  implementation.  If  the  symbolic   constant
       POSIX2_LOCALEDEF  is  defined,  the system supports the creation of new
       locales.    On   XSI-conformant   systems,   the   symbolic    constant
       POSIX2_LOCALEDEF shall be defined.
| improve this answer | |
  • thank, yum whatprovides */localedef reports for glibc-common package, while /usr/bin/localedef doesn't exist. strange, because of docker ? – larrycai Jul 2 '14 at 8:14
  • @larrycai: I'm not sure, haven't seen this problem before. What result ldd /usr/bin/localedef. – cuonglm Jul 2 '14 at 8:28
  • the file doesn't exist, only locale command. If u know docker, you can run docker run -i -t centos bash to check as well. – larrycai Jul 2 '14 at 9:22
  • Thanks sir ~ I was getting quite annoyed by the odd chars :) – Eddie B Aug 26 '15 at 14:10

I provided extra information based on answer @Gnouc (localedef shall be used in centos)

The centos docker is a special image which provides minimal packages, see script https://github.com/dotcloud/docker/blob/master/contrib/mkimage-yum.sh

rm -rf "$target"/usr/{{lib,share}/locale,{lib,lib64}/gconv,bin/localedef,sbin/build-locale-archive}

Inside command localedef is removed, glibc-common package which include this shall be reinstalled

yum reinstall glibc-common

surely the size will be increased

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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