- Linux: Define Locale and Language Settings
- Locale and Language Settings
- Add New Locale
- Ubuntu-18.04
- Ubuntu-14.04
- CentOS-7, CentOS-6
- Set Locale for the Current Session
- Define Locale and Language Permanently
- Set Default System Locale
- Ubuntu-18.04
- Ubuntu-14.04
- CentOS-7
- CentOS-6
- Changing Linux System Language (Locales) From Command Line on Ubuntu and Debian Based Distros
- Changing Linux system language from the terminal
- How to Change or Set System Locales in Linux
- How to View System Locale in Linux
- How to Set System Locale in Linux
Linux: Define Locale and Language Settings
Locales are used in Linux to define which language and character set (encoding) user see in the terminal.
From this article you will learn how to check and change the current locale and language settings from the command line in Linux.
I will show how to check the current locale and language settings and how to get the list of available locals.
You will also see how to set locale and language temporary for the current session only as well as permanently for a single user or for the all users (change default system locale).
Cool Tip: Determine and change a file’s character encoding from the command line in Linux! The best solution for converting text files between different charsets! Read more →
Locale and Language Settings
Execute locale command to get the information about the current locale and language settings:
To list all enabled locales, run:
Locale is defined in the following format:
LANGUAGE | ISO 639 language code |
TERRITORY | ISO 3166 country code |
CODESET | Character set or encoding identifier, like ISO-8859-1 or UTF-8 |
e.g. Australian English with UTF-8 encoding is defined as: en_AU.UTF-8
Add New Locale
New locale: Before a locale can be enabled on the system, it must be generated.
If you didn’t find the desired language or encoding in the list of enabled locales, you can search for them in the list of all supported locales and install whatever you need.
Ubuntu-18.04
Supported releases: Ubuntu-15.04, 15.10, 16.04, 16.10, 18.04.
List the all supported (available for generation) locales:
Find the desired locale, for example:
$ grep de_DE.UTF-8 /etc/locale.gen de_DE.UTF-8 UTF-8
Now you should see it in the list of available locales:
$ locale -a | grep de_DE.utf8 de_DE.utf8
Ubuntu-14.04
Supported releases: Ubuntu-9.10, 10.04, 10.10, 11.04, 11.10, 12.04, 12.10, 13.04, 13.10, 14.04, 14.10.
List the all supported (available for generation) locales:
$ cat /usr/share/i18n/SUPPORTED
Find the desired locale, for example:
$ grep fr_FR.UTF-8 /usr/share/i18n/SUPPORTED fr_FR.UTF-8 UTF-8
Now you should see it in the list of available locales:
$ locale -a | grep fr_FR.utf8 fr_FR.utf8
CentOS-7, CentOS-6
List the all supported (available for generation) locales:
Find the desired locale, for example:
localedef --list-archive | grep hi_IN.utf8 hi_IN.utf8
$ sudo localedef -c -i hi_IN -f UTF-8 hi_IN.UTF-8
Now you should see it in the list of available locales:
$ locale -a | grep hi_IN.utf8 hi_IN.utf8
Set Locale for the Current Session
The locale and language settings are defined in the LANG variable that you can see if you run echo $LANG .
To set the required locale and language for the current session – it is just needed to redefine this variable.
Below you will find the examples of setting locales for some popular languages.
Set the environment variable LANG , as shown in the examples, to change a language and encoding for the current session:
Define Locale and Language Permanently
For this you can set the required value of the LANG variable in a user’s bash profile and the needed locale and language settings will be automatically loaded upon the each session.
Put the following line to the ~/.bashrc or ~/.profile files, to change permanently the locale of the current user to en_US.utf8 :
By default, the modification will take effect after logout/login, but you can force it if you run one of the below commands, depending on in which file you have defined the LANG variable:
Set Default System Locale
Cool Tip: Create the awesome ASCII banners from the Linux command line and decorate your SSH warning messages! Read more →
Perform the following steps to permanently change the system locale (for the all users).
Ubuntu-18.04
Supported releases: Ubuntu-15.04, 15.10, 16.04, 16.10, 18.04.
$ localectl set-locale LANG=en_US.utf8
Ubuntu-14.04
Supported releases: Ubuntu-9.10, 10.04, 10.10, 11.04, 11.10, 12.04, 12.10, 13.04, 13.10, 14.04, 14.10.
Edit the file with default locale settings:
CentOS-7
$ localectl set-locale LANG=en_US.utf8
CentOS-6
Edit the file with default locale settings:
Reboot is required: Note that the above settings will take effect after reboot only.
Changing Linux System Language (Locales) From Command Line on Ubuntu and Debian Based Distros
It’s been some time since I wrote something on It’s FOSS. The truth is that I’ve been writing for a Spanish version of It’s FOSS. If you’ve not visited it and/or you’re a Spanish speaker, please visit It’s FOSS en Español and check all the Linux content in Spanish.
You may be wondering why I’m sharing this fact with you. It’s because this post includes this new page as an example.
At the time of doing a clean installation of your favorite Linux distro, the system asks you to choose a main language. Even though it’s not frequent, some people consider changing that language to a new one later on, like me for example.
See, I have to take screenshots in both Spanish (for It’s FOSS en Español) and in English (for It’s FOSS). This becomes a problem, because I have only one computer, and changing the user is not a fast solution for me.
That’s why I’d like to share with you this quick tip, where I’ll show you how to change your main system language with two simple lines in the terminal.
Changing Linux system language from the terminal
Let’s suppose you want to change your main language from English to Spanish.
Verify which language you have set as default (main language). For this, let’s use the locale command.
You should see something like this.
[email protected]:~$ locale LANG=en_US.UTF-8 LANGUAGE= LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL=
Here you can see that the main language is English. Now to change it, use the dpkg command in this fashion:
sudo dpkg-reconfigure locales
Once you run the command before, you should see the next screen in your terminal.
Here, you should move using the up and down arrow until you reach the desired language. In my case, I desire Spanish, and more specific, Mexican Spanish because I’m Mexican.
Not all languages may have the options, but if yours have, opt for UTF-8.
Once your language has been found, press the SPACE KEY to mark it and then ENTER.
Finally, select this new language as your default by moving to it using the arrow key and pushing the ENTER KEY, in the last windows.
Once done, you should see a message like this in your terminal:
Generating locales (this might take a while). en_US.UTF-8. done es_MX.UTF-8. done Generation complete.
And that’s all! Now you’re able to change your default language as many times you want directly from the terminal.
Please let us know if you have any doubt about this topic in the comments section. Good look!
How to Change or Set System Locales in Linux
A locale is a set of environmental variables that defines the language, country, and character encoding settings (or any other special variant preferences) for your applications and shell session on a Linux system. These environmental variables are used by system libraries and locale-aware applications on the system.
Locale affects things such as the time/date format, the first day of the week, numbers, currency and many other values formatted in accordance with the language or region/country you set on a Linux system.
In this article, we will show how to view your currently installed system locale and how to set system’s locale in Linux.
How to View System Locale in Linux
To view information about the current installed locale, use the locale or localectl utility.
$ locale LANG=en_US.UTF-8 LANGUAGE=en_US LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL= $ localectl status System Locale: LANG=en_US.UTF-8 LANGUAGE=en_US VC Keymap: n/a X11 Layout: us X11 Model: pc105
You can view more information about an environmental variable, for example LC_TIME, which stores the time and date format.
$ locale -k LC_TIME abday="Sun;Mon;Tue;Wed;Thu;Fri;Sat" day="Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday" abmon="Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec" mon="January;February;March;April;May;June;July;August;September;October;November;December" am_pm="AM;PM" d_t_fmt="%a %d %b %Y %r %Z" d_fmt="%m/%d/%Y" t_fmt="%r" t_fmt_ampm="%I:%M:%S %p" era= era_year="" era_d_fmt="" alt_digits= era_d_t_fmt="" era_t_fmt="" time-era-num-entries=0 time-era-entries="S" week-ndays=7 week-1stday=19971130 week-1stweek=1 first_weekday=1 first_workday=2 cal_direction=1 timezone="" date_fmt="%a %b %e %H:%M:%S %Z %Y" time-codeset="UTF-8" alt_mon="January;February;March;April;May;June;July;August;September;October;November;December" ab_alt_mon="Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec"
To display a list of all available locales use the following command.
$ locale -a C C.UTF-8 en_US.utf8 POSIX
How to Set System Locale in Linux
If you want to change or set system local, use the update-locale program. The LANG variable allows you to set the locale for the entire system.
The following command sets LANG to en_IN.UTF-8 and removes definitions for LANGUAGE.
$ sudo update-locale LANG=LANG=en_IN.UTF-8 LANGUAGE OR $ sudo localectl set-locale LANG=en_IN.UTF-8
To configure a specific locale parameter, edit the appropriate variable. For instance.
$ sudo update-locale LC_TIME=en_IN.UTF-8 OR $ sudo localectl set-locale LC_TIME=en_IN.UTF-8
You can find global locale settings in the following files:
- /etc/default/locale – on Ubuntu/Debian
- /etc/locale.conf – on CentOS/RHEL
These files can also be edited manually using any of your favorite command line editors such as Vim or Nano, to configure your system locale.
To set a global locale for single user, you can simply open ~/.bash_profile file and add the following lines.
LANG="en_IN.utf8" export LANG
For more information, see the locale, update-locale and localectl man pages.
$ man locale $ man update-locale $ man localectl
That’s all! In this short article, we have explained how to view and set system local in Linux. If you have any questions, use the feedback form below to reach us.