19

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

bash-4.1# locale -a
C
POSIX

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?

2 Answers 2

38

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:

NAME
       localedef - define locale environment

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

DESCRIPTION
       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.
5
  • thank, yum whatprovides */localedef reports for glibc-common package, while /usr/bin/localedef doesn't exist. strange, because of docker ?
    – larrycai
    Jul 2, 2014 at 8:14
  • @larrycai: I'm not sure, haven't seen this problem before. What result ldd /usr/bin/localedef.
    – cuonglm
    Jul 2, 2014 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, 2014 at 9:22
  • Thanks sir ~ I was getting quite annoyed by the odd chars :) Aug 26, 2015 at 14:10
  • It didn't work for me in ubi8 out of the box. To make it work you have to install glibc-locale-source package. Otherwise localedef will complain: [error] character map file UTF-8 not found: No such file or directory Jan 18, 2022 at 15:22
8

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

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .