The locale on a Linux system is what determines the type of characters and encoding that appear in your command line terminal. Changing the locale will set various environment variables to different values. The terminal and other applications can then query those variables to figure out what type of characters and settings to show the user.
In this tutorial, you will see the step by step instructions on how to list all of the available locales on your Linux system, as well as set and generate a new one to use.
In this tutorial you will learn:
- What is a locale in Linux?
- How to install a new locale
- How to generate locale
- How to list locales
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
How to install, generate and list Locale on Linux
- Let’s start by checking the currently configured locale settings. You can do this with the
localecommand and no further options.
As you can see in the screenshot below, all of the locale settings are displayed to us in the form of environment variables and their assigned values.
- We can get a list of all currently available locales on our system by appending the
$ locale -a
- The list shown above will not include locales which have not yet been generated. To see the full list of available and (currently) unavailable locales, you can view the
$ cat /etc/locale.gen
- As an example, we will generate a locale for Mexican Spanish, which is
$ sudo locale-gen es_MX.UTF-8
- If we check again the list of available locales, we should now see our newly generated locale in the list.
$ locale -a
- The last thing to do is switch our locale. The
localectlcommand can be used to set the locale. In this example, we will proceed with setting the locale to Mexican Spanish.
$ localectl set-locale LANG=es_MX.UTF-8
Executing this command will change the locale for all users on the system. This change will be permanent unless the locale is manually changed again in the future.
- When done, you must reboot your system for the changes to take effect.
- You may get a warning that directory names need to be updated to the new language. You can choose whether or not to approve this change.
- We can now check the locale configuration again, and see that Mexican Spanish has been set for all values.
In this tutorial, we saw how to install, generate, and list available locales on a Linux system. The system locale is what determines the characters and language shown to the user in various programs, and is also reflected in some of the default directory names on certain Linux distributions. It is simple enough to change, but will require a reboot any time you set a new permanent locale.