Working with System Locales in Linux

Most Linux users want a different time zones in different languages and different countries with a different currency. This is where the locale is used as it can be used to change or set language, countries, time/date format, currencies, and many more as per the user preferences. 

Basically, a locale is a set of environmental variables that defines the language, country, and character encoding settings (or any other special variant preferences) for your applications and shell session on a Linux system. These environmental variables are used by system libraries and locale-aware applications on the system.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related System Application configuration queries.

In this context, we shall look into the process of changing or setting such locales on Linux.

How to view the current system locale in Linux ?

With the below command, you can see the current system locale:

$ locale

When you run the above command, you will get different variables that can be reset with different values as per user preference.

Also, using localectl status command, it will result the same:

$ localectl status

How to display all available locales in Linux ?

You can check all available locales on your Linux system with the following command:

$ locale -a

How to display details of specific variables in Linux ?

We can check the details of specific variables using the variable name. In case you want to check details on LC_TIME that stores the time and date format, LC_ADDRESS that stores streets or postal addresses format, LC_TELEPHONE that stores format of telephone settings, and so on.

To get such details, we can run the following commands:

$ locale -k LC_ADDRESS
$ locale -k LC_TIME
$ locale -k LC_TELEPHONE
$ locale -k LC_TIME
$ locale -k LC_ADDRESS

How to change or set system locale in Linux ?

We can change or set system locale in Linux by using the update-locale program. Using the LANG variable, it will allow us to set up the locale for the entire system.

We can set the LANG to en_IN.UTF-8 LANGUAGE and remove the definition for language by using the following command:

$ sudo update-locale LANG=LANG=en_IN.UTF-8 LANGUAGE


$ sudo localectl set -locale LANG=en_IN.UTF-8

How to view Global locale setting ?

We can check or view the global locale setting in the following file on Linux:

$ sudo vim /etc/default/locale 

How to change the locale ?

We can modify the .bashrc profile after already setting the value of locale. Go through the following command:

$ sudo vim ~/.bashrc

How to change the locale for single user ?

To set the global locale for the single user, we can add the following line at the end of ~/.bashrc_profile:

$ sudo vim ~/.bashrc_profile
export LANG

To get more details on locale, update-locale, and localectl, we can check the manual section with the below commands:

$ man locale
$ man update-locale
$ man localectl

[Need assistance in fixing Linux system issues ? We can help you. ]

This article covers how to set a system and view the locale on Linux. In fact, Locale settings usually consist of at least a language code, a country/region code, time / date format, numbers format setting, currency format setting, Color setting, and so on.

To view the information regarding the currently installed locale use the following command on the terminal:

$ locale

For more information, see the locale, update-locale and localectl man pages with the below commands respectively:

$ man locale
$ man update-locale
$ man localectl

Related Posts