Change the keyboard layout in the Linux command line (Ubuntu & CentOS).

Are you stuck in the Linux command line with a keyboard layout you hate? Would you like to change the keyboard layout to one you know better? How can you do this without a graphical interface? It isn’t very complicated!

keyboard layout change

A good command to start with is the following.


The output from this command will be the same as if you would type the following command.

localectl status
localectl in ubuntu

When you run this command, you will see the current settings on your Linux computer. This includes the language of the operating system itself. Besides this, you will see information about your computer’s keyboard layout.

Now let us take a look at a few commands that will help you get the job done.

Change the keyboard layout in the Ubuntu command line.

The commands are very similar, but let us first look at the Ubuntu command line.

sudo apt-get install console-keymaps

This command will take you to an installation process where you can install and add a new keyboard layout to your Ubuntu server or any Ubuntu installation in the command line.

Would you rather do it some other way? Try the following command.

Temporarily change the keyboard layout.

sudo loadkeys us

This will temporarily add a new keyboard layout to your Ubuntu installation. You can change us with the national code of the country you are interested in. When you reboot your computer, the settings will go back to default.

Permanently change the keyboard layout.

If you want to make the changes permanent, run the following command.

sudo localectl set-x11-keymap us
set keymap hu

When the command has run, reboot your device, and the new and permanent settings will be applied. It is also possible to manually make changes to the configuration file.

sudo nano /etc/default/keyboard

In the latter file, change the nation code to the keyboard code you want to use. You need to reboot the computer after entering your requested language code in the file.

How to change the keyboard layout in CentOS?

Now let us do the same in CentOS. The instructions are very similar. A good place to start is with the following command. It might be installed already, but if it isn’t, run this command first.

yum install kbd

Now let us change the keyboard layout. We can use the same commands as in Ubuntu.

loadkeys us (this will change the layout temporarily to a US layout)
loadkeys nl (this will change the layout temporarily to a Dutch layout)
sudo localectl set-x11-keymap no (permanent change to Norwegian)

The temporary solution will immediately happen, but you normally need to reboot the system for the permanent change to happen.

That’s it. Mission accomplished! I hope you will have a better type writing and doing your tasks in both CentOS and Ubuntu after this!

2 thoughts on “Change the keyboard layout in the Linux command line (Ubuntu & CentOS).

  1. Goeldi says:

    My Ubuntu 22.04 server (without x11) has the standard ch (swissgerman) keyboard on its console.
    localectl tells me:
    System Locale: LANG=en_US.UTF-8
    VC Keymap: n/a
    X11 Layout: ch
    X11 Model: pc105
    When I enter loadkeys us it does nothing. It’s still swissgerman (ch). console-keymaps and console-data are already installed. The manual files and google do not suggest a deprecation or another best practice :-/

Leave a Reply