Linux localectl Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to use the localectl command in Linux to manage system locale settings, keyboard layouts, and keymaps. The localectl command is a powerful tool provided by systemd that allows you to configure these important system settings. You will start by understanding the purpose and usage of the localectl command, then learn how to set the system locale and customize the keyboard layout. This lab covers essential skills for system configuration and settings in a Linux environment.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/SystemInformationandMonitoringGroup(["`System Information and Monitoring`"]) linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"]) linux/SystemInformationandMonitoringGroup -.-> linux/date("`Date/Time Displaying`") linux/UserandGroupManagementGroup -.-> linux/set("`Shell Setting`") subgraph Lab Skills linux/date -.-> lab-422764{{"`Linux localectl Command with Practical Examples`"}} linux/set -.-> lab-422764{{"`Linux localectl Command with Practical Examples`"}} end

Understand the Purpose of the localectl Command

In this step, you will learn about the purpose and usage of the localectl command in Linux. The localectl command is a powerful tool provided by systemd that allows you to manage system locale settings, keyboard layouts, and keymaps.

The localectl command is used to:

  • Set the system locale, which determines the language, date/time format, and other locale-specific settings.
  • Configure the keyboard layout and keymap used by the system.
  • Query the current system locale and keyboard settings.

Let's start by checking the current system locale settings using the localectl command:

localectl status

Example output:

   System Locale: LANG=en_US.UTF-8
       VC Keymap: us
      X11 Layout: us

This output shows that the system is currently using the en_US.UTF-8 locale, and the keyboard layout is set to the US English layout.

You can also use localectl to list all available locales and keyboard layouts on the system:

localectl list-locales
localectl list-keymaps

These commands will display the full list of supported locales and keyboard layouts that can be configured on the system.

Manage System Locale Settings with localectl

In this step, you will learn how to use the localectl command to manage the system locale settings.

The system locale determines the language, date/time format, and other locale-specific settings used by the system and applications. Let's start by listing the available locales on the system:

localectl list-locales

This will display a long list of supported locales. To set the system locale, you can use the localectl set-locale command:

sudo localectl set-locale LANG=fr_FR.UTF-8

This will set the system locale to French (France) with the UTF-8 character encoding. You can verify the change by running the localectl status command again:

localectl status

Example output:

   System Locale: LANG=fr_FR.UTF-8
       VC Keymap: us
      X11 Layout: us

Now, let's try using a locale-aware command like date to see the effect of the locale change:

date

Example output:

dim. mai 14 16:24:53 UTC 2023

Notice how the date and time are now displayed in French format.

To revert the locale back to the default en_US.UTF-8, you can run:

sudo localectl set-locale LANG=en_US.UTF-8

Customize Keyboard Layout and Keymaps with localectl

In this final step, you will learn how to use the localectl command to customize the keyboard layout and keymaps on your system.

The keyboard layout determines the physical arrangement of the keys on the keyboard, while the keymap defines the mapping of keys to characters and functions.

Let's start by checking the current keyboard layout and keymap:

localectl status

Example output:

   System Locale: LANG=en_US.UTF-8
       VC Keymap: us
      X11 Layout: us

This shows that the system is currently using the US English keyboard layout and keymap.

To change the keyboard layout, you can use the localectl set-x11-keymap command:

sudo localectl set-x11-keymap de

This will set the keyboard layout to German (de). You can verify the change by running localectl status again:

localectl status

Example output:

   System Locale: LANG=en_US.UTF-8
       VC Keymap: us
      X11 Layout: de

Notice that the X11 Layout field has been updated to de.

If you need to use a more specific keyboard layout, you can specify the full layout name:

sudo localectl set-x11-keymap de nodeadkeys

This will set the German keyboard layout with the "nodeadkeys" variant, which changes the behavior of dead keys.

You can list all available keyboard layouts and keymaps using the following commands:

localectl list-x11-keymap-models
localectl list-x11-keymap-layouts
localectl list-x11-keymap-variants

These commands will display the full list of supported keyboard layouts and keymaps that can be configured on the system.

Summary

In this lab, you learned about the purpose and usage of the localectl command in Linux. The localectl command is a powerful tool provided by systemd that allows you to manage system locale settings, keyboard layouts, and keymaps. You learned how to use localectl to set the system locale, configure the keyboard layout and keymap, and query the current system settings. You also learned how to list the available locales and keyboard layouts on the system.

Additionally, you learned how to use the localectl command to manage the system locale settings. You discovered how to set the system locale to a specific language and character encoding, and how to verify the changes using the localectl status command.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like