Set system locale on Linux

3
(1)

How to set Linux system language using localectl set-locale

Set system locale on Linux

Locales consist of a set of environment variables to define language, country, and character encoding for applications and shell sessions on a Linux system. These environment variables are used by system libraries and country-specific applications on the system.

The locale affects the time and date format, first day of the week, numbers, currency, and many other values formatted according to the language or region (country) set on a Linux system.

Show system locale

The locale and localectl utility provides information about the currently installed locale and changes it when needed.

$ locale
LANG=en_US. UTF-8
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=

Output a list of all available locales.

$ locale -a
C
C.UTF-8
en_US.utf8
POSIX

Change locale using localectl set-locale

If you want to change the locale, the update-locale and localectl command is used. The LANG variable can be used to set the locale for the entire system.

The following command sets LANG to de_DE.UTF-8

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

Set language settings for user only

To set a locale for a single user, you can simply open the file ~/.bash_profile and add the following lines.

$ LANG = "de_DE.utf8"
Export LANG

Set locale using dpkg-reconfigure locales

For Debian 10 and Debian 11, the dpkg-reconfigure service program is a good way to set the system locale.

$ sudo dpkg-reconfigure locales

The locale settings are located in the following files.

  • /etc/default/locale – Ubuntu/Debian
  • /etc/locale.conf – CentOS/RHEL

These files can also be edited manually using a preferred command line editor, such as Vim or Nano, to configure the system locale.

  The next relevant post might also be helpful. This post How to Set Linux Time Zone in Console shows how to query and set the time zone in the command line.

Further help can be found in the man pages.

$ man locale
$ man update-locale
$ man localectl

Conclusion

This tutorial shows how to change and set a locale in Linux using localectl. Each locale consists of a set of environment variables to define the language, country and character encoding for applications and shell sessions on a Linux system.

The localectl utility can be used to query all the necessary information and make settings to set the locale and the appropriate keyboard layout. This is necessary when, for example, incorrect settings were made during installation and/or the default settings were lost due to updates or software installations. localectl is pre-installed on most Linux systems and is only operated via the terminal.

How useful was this post?

Click on a star to rate it!

Average rating 3 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

Leave a Reply

Your email address will not be published. Required fields are marked *