The locale on a Raspberry Pi is what determines the type of characters and encoding that appear in the command line terminal and any applications that check locale settings. Configuring the locale on your Raspberry Pi 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.
The locale will control things like language, character encoding, time format, and other settings which tend to change depending on what part of the world you are in. Obviously, it is ideal for most users to have a properly configured locale so they can see everything formatted in the way they are most familiar with. In this tutorial, you will see the step by step instructions on how to set the locale on a Raspberry Pi, including how to list all available locales and generate new ones as needed.
In this tutorial you will learn:
- What is a locale on Raspberry Pi?
- How to set locale on Raspberry Pi
- How to generate new locale
- How to list all locales
|Requirements, Conventions or Software Version Used
|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
Set Locale on Raspberry Pi step by step instructions
- Let’s start by checking the currently configured locale settings for our Raspberry Pi. 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 Raspberry Pi system by appending the
-aoption to 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 represented as
es_MX.UTF-8. To find the locale you need, just look in the list that was generated with the previous command. Note that the following command requires root permissions.
$ 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 ... es_MX.UTF-8
- 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.
$ sudo localectl set-locale LANG=es_MX.UTF-8
Executing this command will change the locale for all users on the Raspberry Pi. This change will be permanent unless the locale is manually changed again in the future.
- When done, you must reboot your Raspberry Pi for the changes to take effect.
- We can now check the locale configuration again, and see that Mexican Spanish has been set for the
LANGvalue. We can use the same steps above if we need to set the locale for other variables as well.
$ locale -a
In this tutorial, we saw how to set the locale on a Raspberry Pi system. The system locale is what determines the characters and language shown to the user in various programs. It is simple enough to change, although Raspberry Pi OS forces us to change each variable individually, and will require a reboot any time you set a new permanent locale.