862

When I run perl, I get the warning:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

How do I fix it?

5
  • What happened when you checked the locale settings like the error message told you? Commented Mar 23, 2010 at 17:13
  • 4
    instead of installing the locale, you can also change the locale. On my Ubuntu box, this is done for one user by editing ~/.pam_environment Commented Jun 8, 2014 at 12:34
  • On my ODROID-C1 running Ubuntu the issue was indeed the ~/.pam_environment file. Some of the variables were es_US.UTF-8 instead of en_US.UTF-8. Thank you.
    – f1vefour
    Commented Feb 18, 2015 at 13:12
  • 1
    I got this on Cygwin\Babun. Only a reinstall of perl fixed it. Commented Sep 16, 2016 at 20:12
  • If you are here in 2023, it probably means you are SSH:ing into a Raspbian device.
    – conny
    Commented Mar 5 at 9:48

49 Answers 49

1
2
3

In my case, this was the output:

LANGUAGE = (unset),
LC_ALL = (unset),
LC_PAPER = "ro_RO.UTF-8",
LC_ADDRESS = "ro_RO.UTF-8",
....

The solution was:

sudo locale-gen ro_RO.UTF-8
1
  • I also see LANGUAGE = (unset) but don't have the locale-gen command
    – PatS
    Commented Aug 10, 2022 at 14:05
3

Add LC_ALL="en_GB.utf8" to /etc/environment and reboot. That's all.

3

If you don't care about the locale issue, you can set PERL_BADLANG=0. Of course, this could result in incorrect localisation.

3

All the previous answers are wrong. The message is clear - missing locale. The solution is to add the appropriate locale. You do that by editing the /etc/locale.gen file, remove the # sign in front of the locale being reported as missing and then issuing the command:

$ sudo locale-gen

This will actually generate the locales specified in /etc/locale.gen and therefore the message will not be shown.

1
  • This is simply the answer and worked on ancient Debian (6) for me. All the rest are over-complicated and a bit off-track. Commented Apr 12, 2020 at 11:53
3

In my case, with Debian 8.6 (Jessie), I had to change settings in:

/etc/ssh/ssh_config` for `#AcceptEnv LANG LC_*

and

sshd_config for #SendEnv LANG LC_*

Then restart the ssh service.

At last, I did:

locale-gen en_US.UTF-8 and dpkg-reconfigure locales

0
3

In Arch Linux using a UK keyboard and locale, I had the following error:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.utf8"
  • Exporting my locales in /etc/profile didn't fix it.

  • I did however fix this by editing /etc/locale.gen, also enabling the en_US.utf8 locale that perl expected to find, and running local-gen.

(I use pac-manager which uses a whole bunch of perl modules from AUR, so reinstalling perl in my particular case would be a nuisance.)

3
perl -e exit
sudo localedef -i en_US -f UTF-8 en_DE.UTF-8
#                                   DE = German
# Use your country code en lieu of  DE

# The second "perl" should then not complain any more
perl -e exit

localectl list-locales # Just make sure it is OK
2
  • be aware that after this you might run into: "kwin_xkbcommon: XKB: couldn't find a Compose file for locale "en_DE.UTF-8" on KDE , tbh. Yet perl is quite happy with it.
    – dotbit
    Commented Oct 11, 2020 at 6:43
  • Thank you for this post. What is strange (to me) is that simply setting the environment variables in my .bashrc (before running any perl commands involved in my login) did not work. This solution did, so thanks a bunch
    – PatS
    Commented Aug 10, 2022 at 14:11
2

As always, the devil is in the detail...

On Mac OS X v10.7.5 (Lion), to fix some Django error, in my ~/.bash_profile I've set:

export LANG=en_EN.UTF-8
export LC_COLLATE=$LANG
export LC_CTYPE=$LANG
export LC_MESSAGES=$LANG
export LC_MONETARY=$LANG
export LC_NUMERIC=$LANG
export LC_TIME=$LANG
export LC_ALL=$LANG

And in turn for a long time I got that warning when using Perl.

My bad! As I've realized much later, my system is en_US.UTF-8! I fixed it simply by changing from

export LANG=en_EN.UTF-8

to

export LANG=en_US.UTF-8
2

I had multiple users using different shells so in my case this solved:

  • Check which shell
    echo $0
  • if bash
    echo "# Setting locale\nLC_CTYPE=en_US.UTF-8\nLC_ALL=en_US.UTF-8" >> .bashrc
  • if zsh
    echo "# Setting locale\nLC_CTYPE=en_US.UTF-8\nLC_ALL=en_US.UTF-8" >> .zshrc
2

If you are using iTerm2 on MacOS this issue can be solved by unchecking this setting: iTerm2 > Settings > Profiles > Terminal > Set locale variables automatically:

enter image description here

1

ssh overwrites LC locale variables by default. See /etc/ssh/sshd_config:

AcceptEnv LANG LC_*

So maybe you need to set these variables in your local shell.

1

For me, on Ubuntu 16.04 (Xenial Xerus) the following worked:

root@host:~#locale-gen en_GB.UTF-8
root@host:~#localectl set-locale LANG=en_GB.UTF-8,LC_ALL=en_GB.UTF-8

Then reboot...

1

Setting the LC_TYPE environment variable to the default locale language "C" will help to suppress this warning.

Run export LC_CTYPE="C" and try to run the perl command.

P.S: You need to set this variable in one of file /etc/environment or file /etc/default/locale for a permanent solution.

1
  • for csh shell, run the command : setenv LC_CTYPE "C". We can also add the same in ~/.cshrc file and then run the command "source ~/.cshrc" to re-load the variables. Commented Mar 19, 2021 at 10:04
1

I had LC_COLLATE=C set on my machine on /etc/locale.conf. I simply deleted that line, so that only LANG=en_US.UTF-8 (or equivalent for you) is set, and get no more problems.

1

Tried those ways on Mac M1 Monterey, but no one works. My quick way to disable that message: Open Terminal -> Preferences -> Advanced tab -> uncheck to Set locale environment variables on startup

1
  • Thank you, solved for me on my Intel Mac (macOS Monterey 12.7.x)
    – Mark7888
    Commented Aug 8 at 8:51
0

If you are running a chroot in CentOS, try manually copying /usr/lib/locale to the chroot environment for the account that is having this issue.

2
  • 2
    Where to should these be copied?
    – kontur
    Commented Jan 11, 2019 at 11:08
  • Copy it into the chroot environment of the account that you are having trouble with. In my case (with Plesk) this was to /var/www/vhosts/[domain]/usr/lib/, but you will have to determine this path for your server/account.
    – EpicVoyage
    Commented Jan 12, 2019 at 17:34
0

In case someone has a server with Strato and tries to figure this out, check /etc/profile. I was regenerating locales and setting variables for too long before I found out that there are two lines at the end of this file which overwrote my locale settings all the time.

0

Because the warning is only1 emitted by remote Linux systems you connect to, the least intrusive workaround is to not mess with the LC_* variables on your local macOS.

Instead, just tell your SSH client to explicitly set its (forwarded-) environment variables.

In $HOME/.ssh/config, add an override for all hosts:

Host *
  SetEnv LANGUAGE=en_US.UTF-8 LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8

1: well, "most likely-" as of 2023.

-4

Try to reinstall:

localess apt-get install --reinstall locales

Read more in How to change the default locale

0
1
2

Not the answer you're looking for? Browse other questions tagged or ask your own question.