Set and Verify Linux Locale and Keyboard Settings with localectl

localectl is systemd's front door for the machine-wide locale and keyboard settings. You will inspect the current state, pick a locale that actually exists, and change it with something you can verify afterwards, the settings a fresh login and the display manager both read before anything else loads. Allow about ten minutes. The examples describe the installed systemd 255 package, version 255.4-1ubuntu8.17.

1. Inspect the current settings

Start with a read-only status check. Add --no-pager so the output stays visible in a terminal and in copied logs:

$ localectl --no-pager status
System Locale: LANG=en_US.UTF-8
    VC Keymap: (unset)
   X11 Layout: us
   X11 Model: pc105

Your values may differ. The system locale affects system services, the display manager and the default environment after login. Keyboard settings cover the text console and the graphical login screen separately. An unset VC Keymap is not automatically an error: this machine has an X11 layout but no console mapping configured.

Checkpoint: save this output if you are changing a remote machine. It gives you a before-state for comparison and a recovery reference.

2. Choose a locale that is actually installed

Do not guess a locale name. Ask localectl for the available choices:

$ localectl --no-pager list-locales
C.UTF-8
en_US.UTF-8

The list is host-specific. If your required locale is absent, generate or install it with the distribution's normal locale-management tools before calling localectl: this command reads available locale data, it does not make an unavailable locale valid. On this installation, en_US.UTF-8 is available; substitute a value from your own output for LOCALE_VALUE below rather than pasting the placeholder as-is.

3. Set the system locale

set-locale accepts one locale by itself, which sets LANG, or one or more assignments such as LANG=... and LC_MESSAGES=.... This changes system configuration and normally needs elevation:

$ sudo localectl set-locale LOCALE_VALUE

For a concrete example using a value shown by the preceding command:

$ sudo localectl set-locale en_US.UTF-8

There may be no success message, so verify the stored result rather than treating silence as proof:

$ localectl --no-pager status
System Locale: LANG=en_US.UTF-8

To set a particular category instead, use an assignment:

$ sudo localectl set-locale LC_MESSAGES=en_US.UTF-8

Only use an assignment whose locale appears in list-locales. A change to the system setting does not retroactively rewrite every already-running process; start a new login session when you need the new default environment.

4. Select a console keymap

List the virtual-console maps before selecting one:

$ localectl --no-pager list-keymaps | sed -n '1,12p'
Failed to read list of keymaps: No such file or directory

That is a valid failure mode on a system without the console keymap data installed. It means you cannot safely choose a map from this command's output: install the distribution package that supplies the keymaps, then repeat the list command. Do not invent a map name from an X11 layout.

Once the list contains the map you need, set it, with an optional second map for toggling:

$ sudo localectl set-keymap MAP_NAME
$ localectl --no-pager status

Replace MAP_NAME with an exact value from your list. Unless you pass --no-convert, localectl also converts the console map to the closest matching X11 map. That conversion is convenient, but it is an approximation, not a promise that every variant or option survives unchanged.

5. Set an X11 layout when the graphical setting is the source of truth

For an X11 layout, first inspect the available layouts and related values:

$ localectl --no-pager list-x11-keymap-layouts | sed -n '1,12p'
af
al
am
ara
at
au
az
ba
bd
be
br
bt

Then set the layout, with optional model, variant and options, using values supported by your machine:

$ sudo localectl set-x11-keymap LAYOUT MODEL VARIANT OPTIONS
$ localectl --no-pager status

For a plain US layout with the common PC model, the concrete form is:

$ sudo localectl set-x11-keymap us pc105 '' ''

The empty arguments keep the positional interface while leaving variant and options unset; only omit an argument when the command syntax and your intended result are both clear. By default the command also converts the X11 setting to a console map. Use --no-convert when you explicitly want to prevent that:

$ sudo localectl --no-convert set-x11-keymap LAYOUT MODEL VARIANT OPTIONS

6. Check the files and recover a mistake

localectl talks to systemd-localed and updates files such as /etc/locale.conf and /etc/vconsole.conf. Inspect them after a change if you need to distinguish locale data from keyboard data:

$ sudo sed -n '1,80p' /etc/locale.conf
$ sudo sed -n '1,80p' /etc/vconsole.conf

These files hold system configuration, so avoid editing them by hand while another administrator is changing settings. The safer recovery path is to run localectl again with the previously recorded values. For example, if you changed LANG by mistake:

$ sudo localectl set-locale LANG=PREVIOUS_LOCALE_VALUE
$ localectl --no-pager status

Warning: keyboard changes can affect the next console or graphical login. Keep an existing remote session open while testing a new layout, and do not rely on a key combination you have not verified. Changes may also need an initrd rebuild before they affect early boot; localectl does not rebuild the initrd automatically, so use your distribution's documented initramfs tool only when that early-boot behaviour is required.

Done means