How do I change my locale to UTF-8 in CentOS?

Here's the output of locale:

LANG=zh_CN.GBK
LC_CTYPE="zh_CN.GBK"
LC_NUMERIC="zh_CN.GBK"
LC_TIME="zh_CN.GBK"
LC_COLLATE="zh_CN.GBK"
LC_MONETARY="zh_CN.GBK"
LC_MESSAGES="zh_CN.GBK"
LC_PAPER="zh_CN.GBK"
LC_NAME="zh_CN.GBK"
LC_ADDRESS="zh_CN.GBK"
LC_TELEPHONE="zh_CN.GBK"
LC_MEASUREMENT="zh_CN.GBK"
LC_IDENTIFICATION="zh_CN.GBK"
LC_ALL=

How can I change all of them to UTF8? How can I make the locale setting persistent in CentOS 5.5?


Solution 1:

In CentOS try with system-config-language command. That's the CentOS way :) Also you can try with:

localedef -c -f UTF-8 -i en_US en_US.UTF-8
export LC_ALL=en_US.UTF-8

Solution 2:

Do you mean in the current session or permanently?

If you just need it in the current shell you can export the LC_ALL variable. For example:

export LC_ALL=en_US.UTF-8

If you mean to do it permanently or system-wide it varies from distribution from distribution. What's yours?

Solution 3:

Red-Hat like distros (Centos, SL) come with file

/etc/sysconfig/i18n

which contains by default (well, in my case)

LANG="en_GB"

SYSFONT="latarcyrheb-sun16"

And above file is being sourced by /etc/profile.d/lang.sh

I my case I wanted to change en_GB.UTF-8 to en_GB.iso88591 so I found that “proper” way of doing it was to append /etc/sysconfig/i18n with

CHARSET="iso8895-1"

Once that done locale for each account on the system should be saying:

me@wark:~ $ locale

LANG=en_GB.UTF-8

LC_CTYPE="en_GB.iso88591"

LC_NUMERIC="en_GB.iso88591"

LC_TIME="en_GB.iso88591"

LC_COLLATE="en_GB.iso88591"

LC_MONETARY="en_GB.iso88591"

LC_MESSAGES="en_GB.iso88591"

LC_PAPER="en_GB.iso88591"

LC_NAME="en_GB.iso88591"

LC_ADDRESS="en_GB.iso88591"

LC_TELEPHONE="en_GB.iso88591"

LC_MEASUREMENT="en_GB.iso88591"

LC_IDENTIFICATION="en_GB.iso88591"

LC_ALL=en_GB.iso88591

Solution 4:

As I suppose, after your encoding, your are chinese from mainland, you need first the chinese locale :

localedef -i zh_CN -c -f UTF-8 zh_CN.UTF-8

Then you can export you locale as :

export LANG=zh_CN.UTF-8

if you want to configure this system-wide :

change /etc/locale.conf to:

LANG=zh_CN.UTF-8
LC_COLLATE=zh_CN.UTF-8

The second line is for rules about comparing string.

Or for an user, you can just add it in you ~/.bashrc or ~/.profile