What is a “locale” on a Linux operating system? How do I set or get locals (i18n) values on a Linux operating system?
Locales defines language and country specific setting for your programs and shell session. You can use locales to see date, time, number, currency and other values formatted as per your country or language on a Linux or Unix-like system.[donotprint][/donotprint] To set system’s locale you need use shell variable. For example, LANG variable can be used to set en_US (English US) language. This page shows how to set locales (i18n) on a Linux or Unix operating system.
How do I show current locale settings on a Linux or Unix?
The syntax is: locale locale name locale [options] name The locale command displays information about the current locale, or all locales on the screen.
locales command examples
Simply type the following command: $ locale
Display all available locales on your Linux or Unix-like system
Pass the -a option to locale command: $ locale -a Sample outputs:
You also run the following command on a Debian or Ubuntu based system to see the list of all supported locales: $ less /usr/share/i18n/SUPPORTED Sample outputs:
You can also edit /etc/profile and set global locale for all users:
View/set global locale for all users on a “Fedora Linux v22” and “CentOS/RHEL/Scientific Linux 7.x” and above
Type the following command to see the current locale for all users: $ cat /etc/locale.conf Sample outputs:
You can use the following systemd command too: $ localectl status Sample outputs:
System Locale: LANG=en_IN.UTF-8
VC Keymap: in-eng
X11 Layout: in
X11 Variant: eng
To see all locales available, run: $ localectl list-locales To set the default global system locale for all users, type the following command as root: $ sudo localectl set-locale LANG=localeValueHere $ sudo localectl set-locale LANG=en_IN.UTF-8
View/set global locale for all users on a Debian or Ubuntu Linux
To see which locales are supported on Debian/Ubuntu, enter: $ locale -a|more To set the locales for all users, enter: $ sudo locale-gen en_IN $ sudo locale-gen en_IN.UTF-8 Finally run: $ sudo update-locale Another option is to run dpkg-reconfigure locales command and select the locale(s) you want to generate. At the end, you’ll be asked which one should be the default. If you have users who access the system through ssh, it is recommended that you choose None as your default locale: $ sudo dpkg-reconfigure locales
How can I set global locale for one user?
Simply edit your bash shell profile file $HOME/.bash_profile: $ vi ~/.bash_profile Append/add/edit as follows:
OR create a new .i18n file to user’s $HOME directory: $ vi $HOME/.i18n Append/add/edit the following as per your locale setting:
The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.