thumb In different situations (for example, during the installation of Perl applications, or when I use apt-get install) I get the following warning message:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LC_CTYPE = "UTF-8",
	LANG = "ru_RU.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory

This warning message means that you haven’t properly set up locales in your system. To fix this issue you must follow the steps below.

Check the locales

Check which locales you currently have generated by using locale -a:

locale -a
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
C
C.UTF-8
POSIX
ru_RU.utf8

And using locale:

locale
LANG=ru_RU.UTF-8
LANGUAGE=
LC_CTYPE="ru_RU.UTF-8"
LC_NUMERIC="ru_RU.UTF-8"
LC_TIME="ru_RU.UTF-8"
LC_COLLATE="ru_RU.UTF-8"
LC_MONETARY="ru_RU.UTF-8"
LC_MESSAGES="ru_RU.UTF-8"
LC_PAPER="ru_RU.UTF-8"
LC_NAME="ru_RU.UTF-8"
LC_ADDRESS="ru_RU.UTF-8"
LC_TELEPHONE="ru_RU.UTF-8"
LC_MEASUREMENT="ru_RU.UTF-8"
LC_IDENTIFICATION="ru_RU.UTF-8"
LC_ALL=

Programs that support local technology use environment variables to determine the conventions to use for date and time formatting, character display, currency display and codepage selection.

The following environment variables affect locale related behaviour of the system:

  • LANG - Determines the default locale in the absence of other locale related environment variables.
  • LANGUAGE -
  • LC_ADDRESS - Convention used for formatting of street or postal addresses.
  • LC_ALL - High precedence override for locale specific behaviour (overrides all other locale variables).
  • LC_COLLATE - Collation order.
  • LC_CTYPE - Character classification and case conversion.
  • LC_MONETARY - Monetary formatting.
  • LC_MEASUREMENT - Default measurement system used within the region.
  • LC_MESSAGES - Format of interactive words and responses.
  • LC_NUMERIC - Numeric formatting.
  • LC_PAPER - Default paper size for region.
  • LC_RESPONSE - Determines how responses (such as Yes and No) appear in the local language.
  • LC_TELEPHONE - Conventions used for representation of telephone numbers.
  • LC_TIME - Date and time formats.

Setting locales

To see what locales are supported use:

less /usr/share/i18n/SUPPORTED

You will see a long list of the locale names suitable for use in environment variables. In this list, find locale that you need, for example “en”:

en_US
en_US.UTF-8

Now, you will need to generate this locales. You can do this by using locale-gen:

sudo locale-gen en_US.UTF-8
Generating locales (this might take a while)...
  en_US.UTF-8... done
Generation complete.

Alternatively a locale file can be created manually with localedef:

sudo localedef -i en_US -f UTF-8 en_US.UTF-8

This should create the locales and then re-configure them.

Run the command locale -a to verify the list of available locales (note that the spellings change):

locale -a
C
C.UTF-8
en_US.utf8
POSIX
ru_RU.utf8

Verify the new locale:

locale
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
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=en_US.UTF-8

To use the new settings with your programs, re-login (log out and back in) or restart.


Arthur Gareginyan

Arthur Gareginyan

Arthur is a designer and full stack software engineer. He is the founder of MyCyberUniverse.com. His personal website can be found at arthurgareginyan.com. Check out his free WordPress plugins at wordpress.org.

Follow Arthur: