1. Overview

When we use a keyboard, we rely on a keyboard layout to tell us what characters will appear on the screen when we press the keys. A keyboard layout maps symbols and characters to the keys on a keyboard. Different languages, alphabets, and writing systems have different keyboard layouts. Some examples of standard keyboard layouts are QWERTY, AZERTY, QWERTZ, and Dvorak.

The keyboard layout affects how the keys are arranged and what characters they produce when pressed. For example, on a QWERTY keyboard, the key labeled “Q” produces the letter “Q”, but on an AZERTY keyboard, the same key produces the letter “A”.

Sometimes, we might want to change the keyboard layout in the Linux console. This may be to match our preferred language or writing system or for ergonomic or efficiency reasons. In this tutorial, we’ll explore different ways to achieve this.

The codes used in this tutorial are compatible with most Unix-like shells. However, the localectl method may not work on some systems that use systemd as their init system.

2. Using the loadkeys Command

The loadkeys command allows us to load a keyboard layout from a file. To use this method, we need to identify the file name corresponding to the keyboard layout we want to use. The location of the files containing the keyboard layouts differs with distros of Linux OS. However, we can use it without the full path.

For example, to change the keyboard layout to French AZERTY, we can use the following command:

$ sudo loadkeys fr

This method is simple and fast, but it has some drawbacks. First, it only changes the keyboard layout for the current session. If we reboot or log out, the keyboard layout will revert to the default one.

Second, it only affects the console and not the graphical user interface (GUI). If we want to change the keyboard layout for both the console and the GUI, we’ll need another method.

3. Using the setxkbmap Command

The setxkbmap command allows us to set the keyboard layout for both the console and the GUI. The setxkbmap command uses a different naming system for keyboard layouts than the loadkeys command. To use this method, we need to know the two-letter code representing the language of the keyboard layout we want.

To list the available keyboard layouts, we’ll enter the following command on the terminal:

$ localectl list-x11-keymap-layouts

For example, to change the keyboard layout to French AZERTY, we can use the following command:

$ setxkbmap fr

This method is more convenient than using the loadkeys command because it changes the keyboard layout for both the console and the GUI. However, it also has some limitations. First, we must have X Window System installed on our system. We can’t use this method if we don’t have X Window System.

Second, it also only changes the keyboard layout for the current session. If we reboot or log out, the keyboard layout will revert to the default one.

4. Using the dpkg-reconfigure Command

The dpkg-reconfigure command is another option for changing the keyboard layout in the console:

$ sudo dpkg-reconfigure keyboard-configuration

After entering the command, a configuration window will appear. We can use the arrow keys to navigate and the Enter key to select options. Once we’ve selected, we’ll choose “Finish” to apply the change.

This method is more permanent because it changes the default keyboard layout for both the console and the GUI. However, we need to ensure that we don’t make any mistakes that could prevent us from using our keyboard.

5. Editing the /etc/default/keyboard File

The /etc/default/keyboard file contains settings that determine the default keyboard layout for both the console and the GUI. We need to edit this file and change some values according to our preferences to use this method. For example, to change the keyboard layout to French AZERTY, we can change the XKBLAYOUT line to the name of the keyboard layout we want to use:

XKBLAYOUT="fr"

Note that we have to open the file with an administrative privilege. After saving and exiting the file, we need to reboot or log out and log in again for the changes to take effect.

This method is more permanent than the loadkeys or setxkbmap commands because it changes the default keyboard layout for both the console and the GUI. However, it also requires more steps and caution. We need to ensure we edit the file correctly and not make any mistakes that could prevent us from using our keyboard.

6. Using the localectl Command

The localectl command allows us to manage system locale and keyboard settings. To use this method, we need to know the name of the keymap corresponding to the keyboard layout we want. The keymaps are usually located in /usr/share/kbd/keymaps directory. For example, to change the keyboard layout to French AZERTY, we can use the following command:

$ sudo localectl set-keymap fr.map.gz

This method is similar to the loadkeys command but has some advantages. First, it changes the keymap permanently, so we don’t have to rerun it after rebooting or logging out.

Second, it updates other configuration files that depend on the keymap, such as /etc/vconsole.conf and /etc/X11/xorg.conf.d/00-keyboard.conf. Third, it doesn’t require X Window System to be installed on our system.

However, this method also has some drawbacks. First, it only affects the console and not the GUI. Second, it may not work on some systems that use systemd as their init system.

7. Conclusion

In this article, we’ve learned about keyboard layouts and how to change the keyboard layouts in the Linux console using five different methods: using the loadkeys command, using the setxkbmap command, editing the /etc/default/keyboard file, using the dpkg-reconfigure command, and using the localectl command.

We also learned about the advantages and drawbacks of using one over the other.

Comments are closed on this article!