The localectl command in Linux

In a nutshell, the localectl command allows you to control the system locale and keyboard layout settings. One of the main advantages of this command is that it is present in Linux distributions that use systemd. So, you can use it on almost any modern distribution.

The operation of the command is simple and may be used to query and change the system locale and keyboard layout settings.

Now, what can we do with localectl because the system locale controls the language settings of system services and of the UI before the user logs in, such as the display manager, as well as the default for users after login.

It is probably not as well known as other commands, but again, in remote support situations or configurations, it can be a great relief to have this command.

Using the localectl command on Linux

As I mentioned earlier, the localectl command is present in distributions that use systemd. Therefore, you can find it by default in distributions such as Debian, Ubuntu and its derivatives, RHEL and its derivatives, and others such as Arch Linux and openSUSE.

If you run the command without any arguments, then you will get an output screen showing information about the system language, formats, and keyboard layout.

localectl

Sample output

System Locale: LANG=en_GB.UTF-8
                  LC_NUMERIC=en_GB.UTF-8
                  LC_MONETARY=en_GB.UTF-8
                  LC_PAPER=en_GB.UTF-8
                  LC_NAME=en_GB.UTF-8
                  LC_ADDRESS=en_GB.UTF-8
                  LC_TELEPHONE=en_GB.UTF-8
                  LC_MEASUREMENT=en_GB.UTF-8
                  LC_IDENTIFICATION=en_GB.UTF-8
       VC Keymap: n/a
      X11 Layout: en
       X11 Model: pc105

This same output can be obtained if you add the status subcommand

localectl status

In either case, as you can see, it is pretty useful to get information from it.

Another thing you can do is to display the command help via the terminal to give you a general idea of how it works. To achieve this, run.

localectl --help

You will get this output

The localectl command
The localectl command

With localectl we can do two essential things. The first one is to change the locale of the system.

First, it shows the available options

localectl list-locales

Sample Output:

C.UTF-8
en_AG.UTF-8
en_AU.UTF-8
en_BW.UTF-8
en_CA.UTF-8
en_DK.UTF-8
en_GB.UTF-8
en_HK.UTF-8
en_IE.UTF-8
en_IL.UTF-8
en_IN.UTF-8
en_NG.UTF-8
en_NZ.UTF-8
en_PH.UTF-8
en_SG.UTF-8
en_US.UTF-8
en_ZA.UTF-8
en_ZM.UTF-8
en_ZW.UTF-8

You will get a sample output per screen to help you find your own. Remember that the size of the sample output will depend on the languages that have been downloaded to the system.

And to set a new one, just run the following command

localectl set-locale [locale]

For example,

localectl set-locale en_GB.UTF-8

You will probably have to exit the SSH session or restart the computer to apply the changes.

The second important thing you can do with the localectl command is to change the keyboard layout.

It is convenient to, first, display the list of available layouts with the command

localectl list-keymaps

If you are using X11, then you can use the option to modify the keyboard with this argument.

Or display the different models

localectl list-x11-keymap-models

You can also show the available x11 layouts and variants

localectl list-x11-keymap-layouts
localectl list-x11-keymap-variants

And to apply the changes you can run

localectl set-x11-keymap [keymap].

But you can also extend this command to add the model and layout

localectl set-x11-keymap LAYOUT [MODEL] [VARIANT]

This way, it is effortless to use the localectl command to manage the system locale and the keyboard layout.

Conclusion

The localectl command is a systemd tool to manage the keyboard layout, but also to change the system locale. This is essential to get the system right for the job.

I hope you liked this post, and you can share it with all your friends on social networks.

Leave a Comment

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

Scroll to Top