100

I need to change the layout of the keyboard while working in the console on Linux. I need to set up English layout as the default for the console. How can I do it?

J.Olufsen
  • 3,852

10 Answers10

92

To change the system-wide keyboard layout, run

sudo dpkg-reconfigure keyboard-configuration

or edit the XKBLAYOUT line in /etc/default/keyboard.

ephemient
  • 25,622
38

To change your keyboard layout fast, just install setxkbmap with:

sudo apt-get install x11-xkb-utils

After this you can always change the keyboard layout with:

setxkbmap us

To do this automatically every time, extend your .bashrc with:

echo "setxkbmap us" >> ~/.bashrc

Now, open a new console and the US keyboard layout is activated. Don't worry if the small keyboard layout icon in the Ubuntu panel does not change.

Arjan
  • 31,511
Malte Ahl
  • 505
13

Another way, but I understand it won't last for the next boot:

sudo loadkeys /usr/share/keymaps/i386/qwerty/us.kmap.gz

Check /usr/share/keymaps/i386/ for you keyboard layout and keymaps to what suits you better.

8

loadkeys us, it loads US keys but for a single session.

mashuptwice
  • 3,395
7

On current systemd based systems use localectl (as mentioned by @david-tonhofer):

sudo localectl set-keymap us
sudo localectl set-x11-keymap us,de pc104
localectl status
TNT
  • 341
2

The very funny could be to switch back... a possible solution is, to make a Bash script (named with symbols of the target language. For instance, англ).

The second trick is to type "setxkbmap us; setxkbmap ru", and then it's possible to use the Bash history to return the main layout to the console.

Z0dCHiY8
  • 31
  • 1
1

I know this is old, but I'm gonna leave this in case someone else needs it. First answer is correct, it works, the only thing is that in newer versions the "keyboard" file doesn't exist, instead, we have a "console-setup" file where you can also find and edit the XKBLAYOUT option.

0

A better hack is to monitor udev and reset it automatically if the keyboard gets disconnected. Even users on laptops might need it, since it might get instantaneously disconnected. I just made a GitHub repository to do this.

0

After modifying set-up files, rebooting, and the works keyboard layout was not recognized on console. Had Debian 12 virtual machine on VirtualBox.

Solution was to: sudo apt-get install console-setup

Changes took effect immediately after installation.

mhack
  • 1
-1

switch layout:

setxkbmap -layout us && setxkbmap -layout us,ru
setxkbmap -layout ru && setxkbmap -layout ru,us

force switch:

setxkbmap -layout ru && setxkbmap -layout us && setxkbmap -layout us,ru