The localectl command in Linux: configure language and keyboard

Introduction

On modern Linux systems, language, locale, and keyboard layout configuration is managed through the systemd subsystem, and the localectl command is the most direct command‑line interface for inspecting and modifying these parameters. Unlike traditional configuration files such as /etc/locale.conf or /etc/vconsole.conf, localectl allows changes to be made immediately and persistently without manually editing the files, reducing the risk of syntax errors. This post explains step‑by‑step how to use localectl to view the current configuration, set a new locale, change the keyboard layout, and ensure the settings survive reboots.

What is localectl

localectl is part of the systemd toolset and is responsible for querying and modifying environment variables related to internationalization (i18n) and the console keyboard (vconsole). The command reads information from the files /etc/locale.conf and /etc/vconsole.conf, but can also write to them safely. In addition, it shows the system locale, the console locale, the keyboard map (keymap), and the character set (font) currently in use.

Viewing the current configuration

To get a summary of the regional and keyboard configuration, simply run:

localectl status

The output includes lines such as:

  • System Locale: LANG=es_ES.UTF-8
  • VC Keymap: es
  • X11 Layout: es

These values indicate the locale used by system services, the virtual console keyboard map, and the X11 layout (if a graphical environment is being used).

Changing the system locale

If you need to modify the language and regional format (for example, switching from Spanish to US English), use the set-locale subcommand. For example:

sudo localectl set-locale LANG=en_US.UTF-8

This command updates the file /etc/locale.conf with the new variable and, optionally, reloads the environment for processes that read it afterward. You can set multiple variables at once, such as:

sudo localectl set-locale LANG=en_US.UTF-8 LC_TIME=en_US.UTF-8

After applying the change, verify again with localectl status to confirm the locale has been updated.

Modifying the console keyboard layout

The keyboard layout in the virtual console is controlled via the keymap. To change it, use:

sudo localectl set-keymap es

or, if you prefer a different layout:

sudo localectl set-keymap us

The command writes the new configuration to /etc/vconsole.conf. On systems with a graphical environment, you may also want to adjust the X11 layout:

sudo localectl set-x11-keymap es

This last setting adjusts the Xorg configuration file (usually under /etc/X11/xorg.conf.d/) or uses the setxkbmap tools depending on the distribution.

Applying changes persistently

One advantage of localectl is that changes are written directly to the configuration files, so they survive reboots without additional steps. However, some desktop environments may overwrite these settings via their own regional‑settings daemons. In those cases, it is advisable to:

  • Check that the systemd-localed service is active (systemctl status systemd-localed).
  • Consult the documentation of your desktop environment (GNOME, KDE, etc.) to ensure there are no conflicts.
  • Restart the systemd-localed service after making changes (sudo systemctl restart systemd-localed) so the new values propagate to active sessions.

Troubleshooting common issues

If after running localectl set-locale the output of locale still shows the old value, consider:

  • Verify that the locale you are trying to generate is actually installed on the system (locale -a | grep en_US.UTF-8). If it is missing, generate it with sudo locale-gen en_US.UTF-8 or sudo dpkg-reconfigure locales on Debian/Ubuntu.
  • Make sure no environment variables are being overridden in shell startup files (~/.bashrc, ~/.profile).
  • Check the logs of systemd-localed with journalctl -u systemd-localed for error messages.

Regarding the keyboard, if the layout does not change in the console, verify that the specified keymap exists in /usr/share/kbd/keymaps/ and that the file /etc/vconsole.conf contains the correct line, for example KEYMAP=es.

Conclusion

The localectl command is a powerful and simple tool for managing internationalization and keyboard configuration on systemd‑based Linux systems. Its ability to read and write directly to the configuration files makes it the preferred option over manually editing /etc/locale.conf and /etc/vconsole.conf. Whether you need to change the system language, adapt the keyboard to your region, or troubleshoot locale issues, localectl provides a unified and safe interface that guarantees settings persist across reboots and are available both in the console and in graphical environments.

This post is also available in ESPAÑOL.

Leave a Reply

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

Esta obra está bajo una Licencia Creative Commons Atribución 4.0 Internacional para Francesc Roig francesc@vivaldi.net .