Locales are used in Linux to define which language and character set (encoding) user see in the terminal.
From this article you will learn how to check and change the current locale and language settings from the command line in Linux.
I will show how to check the current locale and language settings and how to get the list of available locals.
You will also see how to set locale and language temporary for the current session only as well as permanently for a single user or for the all users (change default system locale).
Cool Tip: Determine and change a file’s character encoding from the command line in Linux! The best solution for converting text files between different charsets! Read more →
Locale and Language SettingsExecute locale
command to get the information about the current locale and language settings:
$ locale
To list all enabled locales, run:
$ locale -a
Locale is defined in the following format:
<LANGUAGE>_<TERRITORY>.<CODESET>[@<MODIFIERS>]
e.g. Australian English with UTF-8 encoding is defined as: en_AU.UTF-8
New locale: Before a locale can be enabled on the system, it must be generated.
If you didn’t find the desired language or encoding in the list of enabled locales, you can search for them in the list of all supported locales and install whatever you need.
Ubuntu-18.04Supported releases: Ubuntu-15.04, 15.10, 16.04, 16.10, 18.04.
List the all supported (available for generation) locales:
$ cat /etc/locale.gen
Find the desired locale, for example:
$ grep de_DE.UTF-8 /etc/locale.gen de_DE.UTF-8 UTF-8
Generate it with:
$ sudo locale-gen de_DE.UTF-8
Now you should see it in the list of available locales:
$ locale -a | grep de_DE.utf8 de_DE.utf8Ubuntu-14.04
Supported releases: Ubuntu-9.10, 10.04, 10.10, 11.04, 11.10, 12.04, 12.10, 13.04, 13.10, 14.04, 14.10.
List the all supported (available for generation) locales:
$ cat /usr/share/i18n/SUPPORTED
Find the desired locale, for example:
$ grep fr_FR.UTF-8 /usr/share/i18n/SUPPORTED fr_FR.UTF-8 UTF-8
Generate it with:
$ sudo locale-gen fr_FR.UTF-8
Now you should see it in the list of available locales:
$ locale -a | grep fr_FR.utf8 fr_FR.utf8CentOS-7, CentOS-6
List the all supported (available for generation) locales:
$ localedef --list-archive
Find the desired locale, for example:
localedef --list-archive | grep hi_IN.utf8 hi_IN.utf8
Generate it with:
$ sudo localedef -c -i hi_IN -f UTF-8 hi_IN.UTF-8
Now you should see it in the list of available locales:
$ locale -a | grep hi_IN.utf8 hi_IN.utf8Set Locale for the Current Session
The locale and language settings are defined in the
LANG
variable that you can see if you run
echo $LANG
.
To set the required locale and language for the current session – it is just needed to redefine this variable.
Below you will find the examples of setting locales for some popular languages.
Set the environment variable LANG
, as shown in the examples, to change a language and encoding for the current session:
Set the English locale:
$ LANG=en_US.utf8
Set the Russian locale:
$ LANG=ru_RU.utf8
Set the French locale:
$ LANG=fr_FR.iso-8859-15
Set the German locale:
$ LANG=de_DE.utf8
Set the Hindi locale:
$ LANG=hi_IN.utf8Define Locale and Language Permanently
If you don’t want to change locale manually for the each session – you can set it permanently.
For this you can set the required value of the LANG
variable in a user’s bash profile and the needed locale and language settings will be automatically loaded upon the each session.
Put the following line to the ~/.bashrc
or ~/.profile
files, to change permanently the locale of the current user to en_US.utf8
:
export LANG=en_US.utf8
By default, the modification will take effect after logout/login, but you can force it if you run one of the below commands, depending on in which file you have defined the LANG
variable:
$ source ~/.profile
– or –
$ source ~/.bashrcSet Default System Locale
Cool Tip: Create the awesome ASCII banners from the Linux command line and decorate your SSH warning messages! Read more →
Perform the following steps to permanently change the system locale (for the all users).
Ubuntu-18.04Supported releases: Ubuntu-15.04, 15.10, 16.04, 16.10, 18.04.
$ localectl set-locale LANG=en_US.utf8Ubuntu-14.04
Supported releases: Ubuntu-9.10, 10.04, 10.10, 11.04, 11.10, 12.04, 12.10, 13.04, 13.10, 14.04, 14.10.
Edit the file with default locale settings:
/etc/default/locale
Set the LANG
variable:
LANG="en_US.utf8"CentOS-7
$ localectl set-locale LANG=en_US.utf8CentOS-6
Edit the file with default locale settings:
/etc/sysconfig/i18n
Set the LANG
variable:
LANG="en_US.utf8"
Reboot is required: Note that the above settings will take effect after reboot only.
Was it useful? Share this post with the world!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4