How to Set Locales (i18n) On a Linux or Unix

Posted on in Categories , , , , , , , last updated September 16, 2015

What is a “locale” on a Linux operating system? How do I set or get locals (i18n) values on a Linux operating system?

Locales defines language and country specific setting for your programs and shell session. You can use locales to see date, time, number, currency and other values formatted as per your country or language on a Linux or Unix-like system. To set system’s locale you need use shell variable. For example, LANG variable can be used to set en_US (English US) language.

How do I show current locale settings on a Linux or Unix?

The syntax is:

locale
locale name
locale [options] name

Examples

Simply type the following command:
$ locale

Fig.01 Show current locale on a Linux or Unix
Fig.01 Show current locale on a Linux or Unix

Display all available locales on your Linux or Unix-like system

Pass the -a option to locale command:
$ locale -a
Sample outputs:

C
C.UTF-8
en_IN
en_IN.utf8
POSIX

You also run the following command on a Debian or Ubuntu based system to see the list of all supported locales:
$ less /usr/share/i18n/SUPPORTED
Sample outputs:

aa_DJ.UTF-8 UTF-8
aa_DJ ISO-8859-1
aa_ER UTF-8
[email protected] UTF-8
aa_ET UTF-8
af_ZA.UTF-8 UTF-8
af_ZA ISO-8859-1
ak_GH UTF-8
am_ET UTF-8
an_ES.UTF-8 UTF-8
an_ES ISO-8859-15
anp_IN UTF-8
ar_AE.UTF-8 UTF-8
ar_AE ISO-8859-6
ar_BH.UTF-8 UTF-8
ar_BH ISO-8859-6
ar_DZ.UTF-8 UTF-8
....
...
el_CY ISO-8859-7
en_AG UTF-8
en_AU.UTF-8 UTF-8
en_AU ISO-8859-1
en_BW.UTF-8 UTF-8
en_BW ISO-8859-1
en_CA.UTF-8 UTF-8
en_CA ISO-8859-1
en_DK.UTF-8 UTF-8
en_DK.ISO-8859-15 ISO-8859-15
en_DK ISO-8859-1
en_GB.UTF-8 UTF-8
en_GB ISO-8859-1
en_GB.ISO-8859-15 ISO-8859-15
en_HK.UTF-8 UTF-8
en_HK ISO-8859-1
en_IE.UTF-8 UTF-8
en_IE ISO-8859-1
[email protected] ISO-8859-15
en_IN UTF-8
...
.....
zh_CN.GB18030 GB18030
zh_CN.GBK GBK
zh_CN GB2312
zh_HK.UTF-8 UTF-8
zh_HK BIG5-HKSCS
zh_SG.UTF-8 UTF-8
zh_SG.GBK GBK
zh_SG GB2312
zh_TW.UTF-8 UTF-8
zh_TW.EUC-TW EUC-TW
zh_TW BIG5
zu_ZA.UTF-8 UTF-8
zu_ZA ISO-8859-1

View/set global locale for all users on a “CentOS/RHEL/Scientific Linux v5.x/6.x” and older

Edit or view /etc/sysconfig/i18n to set global locale for all users:
$ sudo cat /etc/sysconfig/i18n
or
$ sudo vi /etc/sysconfig/i18n
Sample outputs:

LANG="en_US.UTF-8"
SUPPORTED="en_IN.utf8:en_IN:en_US.UTF-8:en_US:en"
SYSFONT="latarcyrheb-sun16"

You can also edit /etc/profile and set global locale for all users:

LANG="en_IN.utf8"
export LANG

View/set global locale for all users on a “Fedora Linux v22” and “CentOS/RHEL/Scientific Linux 7.x” and above

Type the following command to see the current locale for all users:
$ cat /etc/locale.conf
Sample outputs:

LANG="en_IN.UTF-8"

You can use the following systemd command too:
$ localectl status
Sample outputs:

   System Locale: LANG=en_IN.UTF-8
       VC Keymap: in-eng
      X11 Layout: in
     X11 Variant: eng

To see all locales available, run:
$ localectl list-locales
To set the default global system locale for all users, type the following command as root:
$ sudo localectl set-locale LANG=localeValueHere
$ sudo localectl set-locale LANG=en_IN.UTF-8

View/set global locale for all users on a Debian or Ubuntu Linux

To see which locales are supported on Debian/Ubuntu, enter:
$ locale -a|more
To set the locales for all users, enter:
$ sudo locale-gen en_IN
$ sudo locale-gen en_IN.UTF-8

Finally run:
$ sudo update-locale
Another option is to run dpkg-reconfigure locales command and select the locale(s) you want to generate. At the end, you’ll be asked which one should be the default. If you have users who access the system through ssh, it is recommended that you choose None as your default locale:
$ sudo dpkg-reconfigure locales

How can I set global locale for one user?

Simply edit your bash shell profile file $HOME/.bash_profile:
$ vi ~/.bash_profile
Append/add/edit as follows:

LANG="en_IN.utf8"
export LANG

OR create a new .i18n file to user’s $HOME directory:
$ vi $HOME/.i18n
Append/add/edit the following as per your locale setting:

LANG="en_US.UTF-8"
SUPPORTED="en_IN.utf8:en_IN:en_US.UTF-8:en_US:en"
SYSFONT="latarcyrheb-sun16"

Save and close the file. Please note that ~/.bash_profile procedure should work on Linux, OS X, *BSD and many other Unix-like systems.

Leave a Comment