Resolve Setting Locale Failed on Linux

Perl warning Setting locale failed in Debian

Warning Message

The warning message during the installation of Perl applications will appear as follows

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_CTYPE = "UTF-8",
    LANG = "en_US.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

Generating locales

Missing locales are generated with locale-gen:

$ locale-gen en_US.UTF-8

Alternatively a locale file can be created manually with localedef

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

Setting Locale Settings

The locale settings can be set (to en_US.UTF-8 in the example) as follows

$ export LANGUAGE=en_US.UTF-8
$ export LANG=en_US.UTF-8
$ export LC_ALL=en_US.UTF-8
$ locale-gen en_US.UTF-8
$ sudo dpkg-reconfigure locales

The dpkg-reconfigure locales command will open a dialog under Debian for selecting the desired locale. This dialog will not appear under Ubuntu.

Locale warning in RedHat or CentOS

warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory

Run these commands

$ sudo vim /etc/environment

add these lines:

0.00 avg. rating (0% score) - 0 votes