Linux locale
settings determine the current operating system regional settings used in the terminal and GUI (such as date and time format, currency symbols, available character sets, etc.). This article looks at how to check or set locale settings on Linux distros (Ubuntu, Debian, Mint).
Get Current Locale on Ubuntu/Debian
You can view the current locale on Ubuntu and Debian with the command:
$ locale
Or:
$ localectl status
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=en_US.UTF-8
LC_TIME=en_US.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=en_US.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_ADDRESS=en_US.UTF-8
LC_TELEPHONE=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION=en_US.UTF-8
LC_ALL=
- LANG – shows the current system locale (it is en_US.UTF-8)
- LC_NUMERIC – number format
- LC_MONETARY – currency formatting options
- LC_TIME – date and time format
List available locales:
$ locale –a
or
$ localectl list-locales
View detailed information about the locales available on your Linux host:
$ locale -a -v
The system locale C.UTF-8 is always present in this list (the default locale).
Get information about the environment variable that defines the format of the time and the date:
$ locale -k LC_TIME
How to Add a New Locale on Ubuntu/Debian
Let’s try to add the German locale de_DE.UTF-8.
The list of locales available for use is listed in the file:
$ nano /etc/locale.gen
In /etc/locale.gen, uncomment the lines with the locale you need.
Now generate the files and settings for the new locale:
$ sudo locale-gen de_DE.UTF-8
Now you need to set the new locale as the default:
$ sudo update-locale LANG=de_DE.UTF-8
or:
$ sudo localectl set-locale LANG=de_DE.UTF-8
This command will add the following line to the /etc/default/locale:
LANG=de_DE.UTF-8
Reboot the Linux host to apply the new locale settings.
If you specify a locale that has not yet been generated, the locale command will return errors:
$ locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=fr_FR.utf8
You can use a separate locale for different Linux regional options. For example:
$ sudo update-locale LC_NUMERIC=en_US.UTF-8 LC_TIME=en_US.UTF-8 LC_MONETARY=en_US.UTF-8
In some cases, you may need to install the locale package first:
$sudo apt-get install language-pack-fr
If the locale is not set on Linux and the locale -a command returns only three entries:
C
C.UTF-8
POSIX
- Then generate new locale settings:
sudo locale-gen de_DE.UTF-8
- Apply new locale:
sudo update-locale LANG=de_DE.UTF-8
- Reboot the host or open a new terminal prompt.
By default, new users use the locale specified in the /etc/default/locale file.
If you need to change the locale for a specific user, edit the .bashrc file in its home directory:
$ nano .bashrc
LANG=en_US.utf8
Add, Change, and Remove Locales with Dpkg-reconfigure on Ubuntu and Debian
You can use the dpkg-reconfigure command for easier locale management on Debian and Ubuntu. The following command allows you to create, set, or remove locales on Linux:
$ sudo dpkg-reconfigure locales
This tool provides a simple pseudo-graphic for configuring localization settings. Select the locales to install.
Then set the default locale (default locale for the system environment).
To change the encoding (charset) in the terminal, run the command:
$ sudo dpkg-reconfigure console-setup
Select the UTF-8 encoding for the console, and then select the character set support that you would like to add.
These settings are stored in:
$ cat /etc/default/console-setup
Then configure the keyboard:
$ sudo dpkg-reconfigure keyboard-configuration
The recommended keyboard model is the default Generic 105-key PC. Then add the keyboard mappings (keymaps) for the country you want.
Keyboard settings are specified in the file:
$ cat /etc/default/keyboard
You can change your time zone settings in Ubuntu:
$ sudo dpkg-reconfigure tzdata
You can remove locales that you don’t use. The list of installed locales can be found in /usr/lib/locale/locale-archive.
List the locales in the archive:
$ localedef --list-archive
Delete the locale:
$ sudo localedef --delete-from-archive en_IN.utf8