Perl: warning: Setting locale failed in Debian and Ubuntu

last updated in Categories , ,

I am trying to install package and doing some other work. But, getting the error that read as “perl: warning: Setting locale failed. perl: warning: Please check that your locale settings:” How do I fix this problem on my Debian Linux server?

The warning message displayed when Perl based applications called. For example, apt/apt-get internally use Perl to do management of packages in Debian or Ubuntu Linux.

Perl: warning: Setting locale failed in Debian and Ubuntu

Here is a sample session created by apt-get command / apt command:
$ sudo apt-get install iperf
Sample outputs:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  iperf
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/57.2 kB of archives.
After this operation, 164 kB of additional disk space will be used.
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LC_TIME = "en_IN.UTF-8",
	LC_MONETARY = "en_IN.UTF-8",
	LC_MEASUREMENT = "en_IN.UTF-8",
	LC_NUMERIC = "en_IN.UTF-8",
	LC_PAPER = "en_IN.UTF-8",
	LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
locale: Cannot set LC_ALL to default locale: No such file or directory
Selecting previously unselected package iperf.
(Reading database ... 40493 files and directories currently installed.)
Preparing to unpack .../iperf_2.0.9+dfsg1-1_amd64.deb ...
Unpacking iperf (2.0.9+dfsg1-1) ...
Setting up iperf (2.0.9+dfsg1-1) ...
Processing triggers for man-db (2.7.6.1-2) ...
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LC_TIME = "en_IN.UTF-8",
	LC_MONETARY = "en_IN.UTF-8",
	LC_MEASUREMENT = "en_IN.UTF-8",
	LC_NUMERIC = "en_IN.UTF-8",
	LC_PAPER = "en_IN.UTF-8",
	LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LC_TIME = "en_IN.UTF-8",
	LC_MONETARY = "en_IN.UTF-8",
	LC_MEASUREMENT = "en_IN.UTF-8",
	LC_NUMERIC = "en_IN.UTF-8",
	LC_PAPER = "en_IN.UTF-8",
	LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
locale: Cannot set LC_ALL to default locale: No such file or directory
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LC_TIME = "en_IN.UTF-8",
	LC_MONETARY = "en_IN.UTF-8",
	LC_MEASUREMENT = "en_IN.UTF-8",
	LC_NUMERIC = "en_IN.UTF-8",
	LC_PAPER = "en_IN.UTF-8",
	LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").

Understanding locales in Ubuntu and Debian Linux

Locales are a framework to switch between multiple languages and allow users to use their language, country, characters, collation order, date and time, etc. Make sure you set locales generating UTF-8 locales. Other character sets can be set for backwards compatibility with older systems and software.

How to fix Perl: warning: Setting locale failed in Debian and Ubuntu

Type the following commands to fix it. I am using en_US.UTF-8. You can see list of all localisation in /etc/locale.gen using the cat command:
cat /etc/locale.gen
OR
more /etc/locale.gen
Another option is to use grep command to search for specific locales.

## For example, search for English India ##
grep en_IN /etc/locale.gen
 
## Search for English US ##
grep en_US /etc/locale.gen
 
## Search for Japanese ##
grep ja_JP /etc/locale.gen

Perl: warning: Setting locale failed in Debian

Understanding “ja_JP.UTF-8” or “en_US.UTF-8”

The ja_JP.UTF-8 defined character encoding for Japanese language users as follows:

  1. Locale is ja_JP
  2. Encoding is UTF-8

Similarly, en_US.UTF-8 is for English user from USA:

  1. So locale is set to en_US
  2. And encoding is set to UTF-8

To view current information about the current locale, or all locales, on your screen run locale command:
locale
Sample outputs:

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

How to generate locales on Debian or Ubuntu Linux

Run the locale-gen command to generate locales from /etc/locale.gen for English USA user:
$ sudo locale-gen
OR
$ sudo locale-gen en_US.UTF-8
One can run the following too:
$ sudo localedef -i en_US -f UTF-8 en_US.UTF-8

How to fix a locale setting warning from Perl in Debian and Ubuntu Linux

Personally, I fixed it as follows using combination of the export command, locale-gen command and dpkg-reconfigure command:
$ sudo export LANGUAGE=en_US.UTF-8
$ sudo export LANG=en_US.UTF-8
$ sudo export LC_ALL=en_US.UTF-8
$ sudo locale-gen en_US.UTF-8

Sample outputs:

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

Open the dialog box:
$ sudo dpkg-reconfigure locales
Setting Locale Settings on Ubuntu Linux
Next, set defaults to fix a locale setting warning from Perl:
How to fix a locale setting warning from Perl
Now you set up correct locales and test with apt/apt-get:
$ sudo apt install foo

Conclusion

This page showed you how to use the dpkg-reconfigure and other commands to set up the desired locale. Setting up correct locales is essential. Hence, you ran into the problem, and we configured the locales in Debian or Ubuntu to fix it. For more information see this and this page about locale encodings.

Posted by: Vivek Gite

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.

Notable Replies

  1. Hey nixCraft,
    thx again for very clear instructions.

    … locale-gen command and [nixmd name=”dpkg-reconfigure”]:

    I have the feeling that something slipped through your editing process. Am I right? :wink:

  2. Hehe… yes, I did. Thanks for the heads up!

Continue the discussion www.nixcraft.com

Participants

Historical Comment Archive