How to change locale environment variable?

You can set any locale category independently. LANG applies only to the categories that are not explicitly set.

LANG and LC_xxx are ordinary environment variables. They are not settings for the locale utility: the locale program isn't involved in any locale processing, it's just a small utility to report current and available locale settings.

When you write LC_TIME=ru_RU.utf8, this doesn't set an environment variable, only a shell variable. Shell variables are internal to the shell, they are not seen by other programs. Environment variables, on the other hand, are inherited by the programs that the shell starts. You need to export the variable to the environment as well:

$ LC_TIME=ru_RU.utf8
$ locale | grep LC_TIME
LC_TIME="et_EE.iso88591"
$ export LC_TIME
$ locale | grep LC_TIME
LC_TIME="ru_RU.utf8"

or directly

$ export LC_TIME=ru_RU.utf8
$ locale | grep LC_TIME
LC_TIME="ru_RU.utf8"

Under the Fedora/CentOS/RHEL based distros I believe you can change the locale to one of the locale's displayed when you run the locale -a command in this system file:

/etc/sysconfig/i18n

For example on my Fedora 14 system:

$ more /etc/sysconfig/i18n 
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"

Under GNOME you can run the help app:

system-config-language

Which brings up this GUI:

             ss of lang. gui

I think it's slightly different for the Debian/Ubuntu distros. I believe it's this file:

/etc/default/locale

I believe they're environment variables but not entirely sure how applications make use of them if at all.

References

  • What is a "locale?
  • Character encoding and locales

On RedHat 6 at least, note that if LC_ALL is set, then setting other LC_* environment variables will have no effect, as LC_ALL takes precedence over all other LC_* environment variables.

[root@nbu76 bin]# LC_TIME=en_US.UTF-8
[root@nbu76 bin]# export LC_TIME
[root@nbu76 bin]# locale
LANG=en_US.UTF-8
LC_CTYPE="en_IE"
LC_NUMERIC="en_IE"
LC_TIME="en_IE"
...
LC_ALL=en_IE
[root@nbu76 bin]# unset LC_ALL
[root@nbu76 bin]# locale
LANG=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
LC_NUMERIC="en_US.UTF-8"
LC_TIME=en_US.UTF-8
...
LC_ALL=
[root@nbu76 bin]# export LC_TIME=en_IE
[root@nbu76 bin]# locale
LANG=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
LC_NUMERIC="en_US.UTF-8"
LC_TIME=en_IE
....
LC_ALL=