change or update locale settings

How to Update or Change System Locale in Linux

Every Linux system has a set of environment variables known as locale that stores information about the system’s language, country, character encoding and other settings. This information is used by shell scripts, applications, system libraries and other processes that need information based on system’s location. For example, locale also affects the system’s date/time, first day of the week, currency and other variables that depend on the system’s location. Sometimes you may need to change the locale of your system. In this article, we will learn how to update or change system locale in Linux. You may need to set the locale of your system especially if you are running a website on it, because both your web server and database will refer to locale variables to set their own time zone, language, encoding, etc. Without locale settings, you will need to separately set these values for each of your applications, which is very tedious and unnecessary.

How to Update or Change System Locale in Linux

You can easily get locale information of your system using 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"
...

$ localectl status

System Locale: LANG=en_US.UTF-8
      LANGUAGE=en_US
      VC Keymap: n/a
      X11 Layout: us
      X11 Model: pc105

The locale command above will display the locale setting for each system variable such as TIME, ADDRESS and even units of MEASUREMENT.

If you want to view specific information about environment variable, you can use it as an argument after -k option. Here is the command to get value of LC_TIME variable.

$ 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"

If you want to view the list of all available locales, use the -a option.

$ locale -a

C
C.UTF-8
en_US.utf8
POSIX


How to Update or Set System Locale in Linux

If you want to change or set system locale in Linux, use update-locale program, followed by the specific environment variable that you want to set. Here is a command to set the LANG variable that allows you to set the locale for entire system. The following command sets LANG to en_IN.UTF-8 and removes definition for language.

$ sudo update-locale LANG=LANG=en_IN.UTF-8 LANGUAGE
OR
$ sudo localectl set-locale LANG=en_IN.UTF-8

If you want to update a specific variable, mention it after update-locale command. For example, here is the command to set LC_TIME variable to en_IN.UTF-8

$ sudo update-locale LC_TIME=en_IN.UTF-8
OR
$ sudo localectl set-locale LC_TIME=en_IN.UTF-8

You will find the global locale settings in

  • /etc/default/locale – on Ubuntu/Debian
  • /etc/locale.conf – on CentOS/RHEL

You can also manually edit these files using any text editor to update or change system locale variables.

Alternatively, if you want to change system locale for just one user, you can also edit that user’s ~/.bash_profile and add the following lines.

LANG="en_IN.utf8"
export LANG

If you need more information about update-locale command, you can check out its man pages, which will give you a good idea about it available options.

$ man locale
$ man update-locale
$ man localectl

In this article, we have learnt how to view and set system locales in Linux. By changing the locale variables you can easily customize the system as per your requirement. This is really useful especially if you are running a server or database on your Linux system because your server and database will use locale environment variables to determine their own time zone and related variables.

Also read:

Linux Grep Binary Files for Strings
Linux Prevent File from Being Modified
Linux Rename File with Special Characters
Linux Rename File Starting with Dash
How to Disable Shutdown & Reboot Commands in Linux

Leave a Reply

Your email address will not be published. Required fields are marked *