Raspberry Pi is a popular single-board computer that empowers people of all ages to explore computing. It is characterized by a large selection of models, each with its own specifications and capabilities, making it suitable for numerous applications.

However, regardless of how you intend to use your Raspberry Pi, the hardware requires an operating system before it can run any programs. Fortunately, the Raspberry Pi Foundation officially provides the Raspberry Pi OS (formerly Raspbian) that runs on all Raspberry Pi models.

Why Change Your Keyboard Layout?

a mechanical keyboard

When you first install Raspberry Pi OS on your Raspberry Pi, its keyboard is set to QWERTY – English (UK), reflecting Raspberry Pi's origin.

But since not everyone prefers the QWERTY layout, and not all regions have the same special character keys on their keyboards as the English (UK) keyboard, using the default keyboard setting can be annoying and/or challenging. Thus, it's best to change the keyboard layout of the Raspberry Pi before you start working on it.

How to Change Keyboard Layouts on Raspberry Pi OS

Since Raspberry Pi OS is available in three different versions—Raspberry Pi OS with desktop and recommended software, Raspberry Pi OS with desktop, and Raspberry Pi OS Lite—the approach to changing the keyboard layout on each of them depends on the onboard programs.

Related: The Raspberry Pi Board Guide: Zero vs. Model A and B

Of the three Raspberry Pi OS versions, the first two offer a desktop environment that makes it easy to change keyboard layouts. The Lite version lacks a desktop environment, so you'll need to use a non-GUI method to change the keyboard layout.

At large, there are three ways to change the default keyboard layout on a Raspberry Pi running Raspberry Pi OS. We'll go over the steps for each of them to guide you through.

1. Using Raspberry Pi Desktop

For a full-fledged (aka non-headless) Raspberry Pi OS installation on your Raspberry Pi, the easiest way to change its keyboard layout is using its desktop environment.

So if you have either the "Raspberry Pi OS with desktop" or the "Raspberry Pi OS with desktop and recommended software" version installed on your Raspberry Pi, you should opt for this method.

  1. With your Raspberry Pi running, click the Raspberry Pi icon in the top-left corner of the screen.
  2. From the dropdown menu, choose Preferences > Mouse and Keyboard Settings. In the Mouse and Keyboard Settings dialog box, select the Keyboard tab. And on the next screen, click on the Keyboard Layout button.
    changing Raspberry Pi keyboard layout using Raspberry Pi Desktop
  3. Alternatively, if the Mouse and Keyboard Settings option is absent in the Preferences menu, you can select Raspberry Pi Configuration. And after this, in the Raspberry Pi Configuration window, go to the Localisation tab and click on Set Keyboard.
  4. Now, you have three different settings. To change them, click the dropdown button next to each one.
    • Model: Defines the keyboard model to use; should be set to Generic 105-key PC (intl) — unless you are using a special keyboard.
    • Layout: Defines the keyboard layout based on the region; should be set to the default keyboard layout for your country.
    • Variant: Defines the type of layout your keyboard uses; should be set to English (US) — unless you use other keyboard formats like DVORAK.
  5. Click OK.

2. Using the Raspi-Config Tool

If you have "Raspberry Pi OS Lite" installed on your Raspberry Pi, it does not have a desktop (graphical interface) that you can use to interact with the system. So, in this case, the best way to change the keyboard layout is using the raspi-config tool.

For this, connect your Raspberry Pi directly to a monitor or SSH into it from another device. On the raspi-config window, use the arrow keys to navigate the menu and the enter/return key to select items.

  1. In the command line, type sudo raspi-config. If it is your first boot, you should see this screen automatically.
  2. Navigate the configuration menu and select Location Options.
    changing Raspberry Pi keyboard layout using raspi-config
  3. On the next screen, choose Change Keyboard Layout.
  4. Ensure that the default keyboard layout is Generic 105-key PC (intl.). For the keyboard layout, select an option from the list. [In general, English (US) works best for most people.] And in the variant selection, select QWERTY unless you use some other variant.
  5. From here on out, you can leave the default configurations for the rest of the keyboard settings.
  6. Select Finish to save your changes and exit.

3. Using the Keyboard Configuration File

Although the above two methods work perfectly well in most cases, for times when they don't, you can edit the configuration file to change the keyboard configuration. If you are using "Raspberry Pi OS Lite" on your Raspberry Pi and the raspi-config tool method doesn't work for some reason, you can use this method to change your keyboard layout.

Related: Setup VNC on Raspberry Pi to Remotely Control It With Any PC or Phone

To do this, first, connect your Raspberry Pi to a monitor or log in through SSH from another computer. And then, follow the steps below.

  1. Enter the following command in the command line to open the keyboard configuration file: sudo nano /etc/default/keyboard.
  2. On the edit page, edit the value for XKBLAYOUT and set it to "us" for English (US). The configuration file should look something like this:
            XKBMODEL="pc105"
    XKBLAYOUT="us"
    XKBVARIANT=""
    XKBOPTIONS=""
    BACKSPACE="guess"
  3. Hit CTRL + S to save and CTRL + X to exit the file.
  4. Enter the following terminal command to restart your Raspberry Pi: sudo reboot.

Raspberry Pi Keyboard Layout, Configured

Incorrect keyboard configuration on computers is known to create confusion and cause inconvenience as the key presses on your keyboard may not correspond to letters on the screen. And it holds true to even the Raspberry Pis.

Most of the confusion caused by misconfigured keyboards stems from the special character keys since they do not share the same placement on the keyboard across all regions. So, if you'll need to use the special character keys on your keyboard, configuring it to your region is a crucial step before you start working on your Raspberry Pi.