How Change Keyboard Layout Linux: Ultimate Guide for Beginners

Changing Keyboard Layout in Linux: A Comprehensive Guide

Linux offers several methods to change the keyboard layout, catering to various user needs and preferences. This guide will walk you through the different ways to change your keyboard layout, ensuring you can easily switch between layouts to suit your linguistic or personal requirements.

Using the setxkbmap Command

The setxkbmap command is one of the most versatile and widely used methods for changing the keyboard layout. Here’s how you can use it:

  1. Check Current Keyboard Layout:
    To understand the current layout before making any changes, use the following command:

    setxkbmap -query
    

    This will display information about the current keyboard layout, including the layout variant and options.

  2. List Available Keyboard Layouts:
    To see a list of available keyboard layouts, you can use:

    localectl list-x11-keymap-layouts
    

    or

    cat /usr/share/X11/xkb/rules/xorg.lst
    

    Note down the layout you want to switch to.

  3. Change Keyboard Layout:

Use the setxkbmap command to change the layout. For example, to change to the US keyboard layout:

setxkbmap us

Replace us with the layout code of the desired layout (e.g., gb for UK, de for German).

  1. Verify New Keyboard Layout:
    After making the adjustment, verify that the keyboard layout has taken effect by running:
    setxkbmap -query
    

    This ensures the new layout is correctly applied.

Using GUI Settings

If you prefer a graphical interface, you can change the keyboard layout through your desktop environment settings. Here’s how to do it in a typical GNOME environment on Ubuntu:

  1. Open Settings:
    Open the applications launcher and search for Settings.

  2. Navigate to Keyboard Settings:
    In the settings menu, find the Keyboard section along the left side and click it.

  3. Add a New Keyboard Layout:

Click on the + plus sign to add a new keyboard layout. Expand the choices by clicking on the three dots and select your desired language. If you do not see your desired language listed, click on Other at the bottom of the Add an input source window.

  1. Verify and Manage Layouts:
    You should now see that your selected keyboard layout has been added. You can add more layouts or delete existing ones by clicking on the trash bin icon next to each layout in the list.

Editing the /etc/default/keyboard File

For a more permanent solution, you can edit the /etc/default/keyboard file. Here’s how:

  1. Open the Terminal:
    Launch the terminal using the application menu or a shortcut key combination like Ctrl + Alt + T.

  2. Access Root Privileges:
    To edit system configuration files, you need root privileges. Use:

    sudo nano /etc/default/keyboard
    
  3. Locate and Edit the XKBLAYOUT Line:

Search for the line that starts with XKBLAYOUT=. Change the value to your desired layout (e.g., XKBLAYOUT="gb" for UK layout). Save the file by hitting Ctrl + O and then Enter, and close Nano with Ctrl + X.

Using localectl Command

The localectl tool allows you to set the console and Xorg keyboard layout. Here’s how to use it:

  1. Set Console Layout:
    To set the console layout to UK English, for example:

    sudo localectl set-keymap --no-convert uk
    
  2. Set Xorg Layout:
    To set the Xorg layout to UK English:

    sudo localectl --no-convert set-x11-keymap uk
    

    This method ensures the layout is applied consistently across both console and GUI sessions.

Using dpkg-reconfigure Command

For systems using the keyboard-configuration package, you can use the dpkg-reconfigure command:

  1. Open the Terminal:
    Launch the terminal.

  2. Run dpkg-reconfigure:
    Use the following command to launch the configuration utility:

    sudo dpkg-reconfigure keyboard-configuration
    

    Choose your desired keyboard layout and press Ok.

Making Changes Persistent

To ensure your keyboard layout changes persist across reboots, you can add the setxkbmap command to your user’s shell configuration file (e.g., ~/.bashrc or ~/.bash_profile). For example:

echo "setxkbmap gb" >> ~/.bashrc

This will apply the UK keyboard layout every time you log in.

Troubleshooting

If your keyboard layout does not change after running the command, ensure you are using the correct layout code. Also, check for any errors or warnings in the terminal output. If issues persist, refer to the FAQs or seek help from the Linux community.

Leave a Reply

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