How to install, generate and list Locale on Linux

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
How to install, generate and list Locale on Linux
How to install, generate and list Locale on Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to install, generate and list Locale on Linux



  1. Let’s start by checking the currently configured locale settings. You can do this with the locale command and no further options.
    $ locale
    

    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.

    Viewing locale settings in terminal
    Viewing locale settings in terminal
  2. We can get a list of all currently available locales on our system by appending the -a option.
    $ locale -a
    
    Viewing the available locales installed on our system
    Viewing the available locales installed on our system
  3. 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 /etc/locale.gen file.
    $ cat /etc/locale.gen
    
    All of the locales available to be generated
    All of the locales available to be generated
  4. As an example, we will generate a locale for Mexican Spanish, which is es_MX.UTF-8.


    $ sudo locale-gen es_MX.UTF-8
    
    Generating a locale for Mexican Spanish - the proper characters must be generated by the system
    Generating a locale for Mexican Spanish – the proper characters must be generated by the system
  5. If we check again the list of available locales, we should now see our newly generated locale in the list.
    $ locale -a
    
    The generated locale is now in the list of available locales
    The generated locale is now in the list of available locales
  6. The last thing to do is switch our locale. The localectl command 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
    
    WARNING
    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.
  7. When done, you must reboot your system for the changes to take effect.
    $ reboot
    
  8. 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.
    Updating our locale has prompted our Linux system to change directory names
    Updating our locale has prompted our Linux system to change directory names
  9. We can now check the locale configuration again, and see that Mexican Spanish has been set for all values.
    $ locale
    
    Viewing our newly set locale on Linux
    Viewing our newly set locale on Linux


Closing Thoughts

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.



Comments and Discussions
Linux Forum