Linux: setlocale: LC_ALL: cannot change locale (en_US.utf8) and Cyrillic symbols

By | 02/04/2021

Locales is a set of environment variables that are used to determine how to display data and time (for example, first of the week), symbols encoding (for example, how to display cyrillic symbols), default files order when one executing the ls command, and so on.

Those variables are:

  • LANG: Determines the default locale in the absence of other locale related environment variables
  • LANGUAGE: List of fallback message translation languages
  • LC_CTYPE: Character classification and case conversion
  • LC_NUMERIC: Numeric formatting
  • LC_TIME: Date and time formats
  • LC_COLLATE: Collation (sort) order
  • LC_MONETARY: Monetary formatting
  • LC_MESSAGES: Format of interactive words and responses
  • LC_PAPER: Default paper size for region
  • LC_NAME: Name formats
  • LC_ADDRESS: Convention used for formatting of street or postal addresses
  • LC_TELEPHONE: Conventions used for representation of telephone numbers
  • LC_MEASUREMENT: Default measurement system used within the region
  • LC_IDENTIFICATION: Metadata about the locale information
  • LC_RESPONSE: Determines how responses (such as Yes and No) appear in the local language (not in use by Debian GNU/Linux but Ubuntu)
  • LC_ALL: Overrides all other locale variables (except LANGUAGE)

Locale and Cyrillic symbols

For example, when running a vifm tool in the KDE Konsole on my Arch Linux – cyrillic symbols are not displayed correctly:

And after exiting from the vifm terminal produces an error message:

/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.utf8)

Generate Locale

Check the  /usr/lib/locale/ where already generated locales must be stored – nothing here now:

ll /usr/lib/locale/
total 0

Or you can check by calling the locale -a to display locales that are available in the system now:

locale -a

Now, to add a new locale edit the locales.gen – find en_US.UTF-8:

cat /etc/locale.gen | grep en_US.UTF-8
en_US.UTF-8 UTF-8
en_US.UTF-8 UTF-8

Uncomment the en_US.UTF-8 UTF-8string and run locales generator:

sudo locale-gen
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.utf8)
Generating locales...
en_US.UTF-8... done
Generation complete.

Check the directory again:

file /usr/lib/locale/locale-archive
/usr/lib/locale/locale-archive: locale archive 11 strings

And locale -a:

locale -a

Or by using the localedef utility:

localedef --list-archive

And run the vifm again:

Locales parameters

You can check various parameters for a specific locale by calling locale -k:

locale -k LC_TIME

Locales are described in a corresponding file in the /usr/share/i18n/locales/ catalog which is used during locale-gen. For example, for the en_US its LC_TIME locale is described as:

abday   "Sun";"Mon";"Tue";"Wed";"Thu";"Fri";"Sat"
day     "Sunday";/

week 7;19971130;1
abmon   "Jan";"Feb";/
mon     "January";/
% Appropriate date and time representation (%c)
d_t_fmt "%a %d %b %Y %r %Z"
% Appropriate date representation (%x)
d_fmt   "%m//%d//%Y"
% Appropriate time representation (%X)
t_fmt   "%r"
% Appropriate AM/PM time representation (%r)
t_fmt_ampm "%I:%M:%S %p"
% Appropriate date and time representation for date(1).  This is
% different from d_t_fmt for historical reasons and has been different
% since 2000 when date_fmt was added as a GNU extension.  At the end
% of 2018 it was adjusted to use 12H time (bug 24046) instead of 24H.
date_fmt "%a %b %e %r %Z %Y"
% Strings for AM/PM
am_pm   "AM";"PM"

And for the ru_RU its LC_TIME has the first_weekday option set, see man 5 locale, which specifies the first day of the week – Monday (which is second in the list):

week 7;19971130;1
first_weekday 2

To set Monday as the first day of the week, set the LC_TIME as ru_RU.UTF-8 in the /etc/locale.conf file. At first, uncomment it in the /etc/locale.gen and then execute the locale-gen:


Or by using the localectl tool:

localectl set-locale LC_TIME=ru_RU.UTF-8

Useful links

Also published on Medium.