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:
-
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.
-
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.
-
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).
- 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:
-
Open Settings:
Open the applications launcher and search forSettings
. -
Navigate to Keyboard Settings:
In the settings menu, find theKeyboard
section along the left side and click it. -
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.
- 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:
-
Open the Terminal:
Launch the terminal using the application menu or a shortcut key combination likeCtrl + Alt + T
. -
Access Root Privileges:
To edit system configuration files, you need root privileges. Use:sudo nano /etc/default/keyboard
-
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:
-
Set Console Layout:
To set the console layout to UK English, for example:sudo localectl set-keymap --no-convert uk
-
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:
-
Open the Terminal:
Launch the terminal. -
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.