Locales are used in Linux to define which language and character set (encoding) the user uses.
In this article, I’ll show you how to :
- Check the Current Locale
- Get the List of Available Locales
- Add a New Locale
- Change the Locale for Current Session
- Change the Locale Permanently
- Change the Default System’s Locale
Get the information about the current locale environment :
Locale is defined in the following format :
For example : Australian English using the UTF-8 encoding is en_AU.UTF-8
Look for available locales :
$ locale -a
Adding New Locale
If you didn’t find the desired language or encoding, you can search for them in the list of all supported locales :
Generate a new locale by running locale-gen command. For example :
# locale-gen en_US.UTF-8 # locale-gen ru_RU.UTF-8 # locale-gen fr_FR ISO-8859-1
Now you could see it in the list of available locales.
$ locale -a
Change Locale for Current Session
# Set English locale $ LANG=en_US.utf8 # Set Russian locale $ LANG=ru_RU.utf8 # Set France locale $ LANG=fr_FR.iso-8859-15
Change Locale Permanently
Put the following line to bash profile (~/.bashrc or ~/.profile), to change user’s locale permanently :
Changes will take effect after logout/login.
Change Default System’s Locale
Perform the following steps to permanently change system’s locale.
Edit the file with default locales :
Change the LANG variable:
Changes will take effect after reboot.