How to fix a locale error for Perl-based programs to work properly

botond published 2021/03/28, v - 15:53 time

Content

 

Introductory

If our locales are not set correctly or are set up after installing or updating a program, Perl-based programs will report an error. In this short guide, we will look at the solution to this error.

 

 

The symptom

On Linux systems, a lot of programs are written in Perl, so this error can occur in several places. The error message is dropped by the Perl shell, which is usually the following:

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").

For example, I have Asbrú Connection Manager program reported an error when I connected to a server. Part of the mentioned connection management program was made in Perl, so this error also appeared in this, supplemented by other error messages of the program that resulted from it. So the complete error message looked like this to me:

Locale error while logging in to SSH in Asbrú Connection Manager

In this example, I logged in from my laptop to my desktop computer after a major package update, at which point it threw this error. Login was successful, but the error message appeared every time I connected to any server.

 

Solution #1

Az Abras client program it was mostly made in Perl, so he threw the bug. Of course, this error can occur with other Perl-based programs, so this solution can be applied elsewhere in the event of such an error. 

To resolve this, run localdef command rootwith the appropriate switches:

First, set the system to English:

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

Then in Hungarian:

localedef -i hu_HU -f UTF-8 hu_HU.UTF-8

Change locale with the localedef command

Smoothly setting it to Hungarian did not improve the problem for me, but so that I set it to English before, then the error disappeared.

It then resets the character tables, etc., which can already be used by the C libraries used in Perl.

Then the Perl programs run without error, so for example I have SSH login on a new tab with the Asbrú client:

SSH login without error

 

 

Solution #2

If the first solution does not work, or if the problem reoccurs over time, we can also remedy this error in the following way. For example, it came up again after about a year, and now I used this:

So the error looked like this:

Ásbrú locale error

Check our locale settings with the locale -a command:

locale -a

The locale -a command

If the locale setting in Ásbrú's error message is not included here (for me the "en_US.UTF-8"), then set it rootas in the locale.gen file:

nano /etc/locale.gen

Edit locale.gen

Then remove the comment (#) from the corresponding line:

Edit locale.gen

Then run the locale-gen command:

locale-gen

Run the locale-gen command

And after that, Ásbrú works without error:

Ásbrú - Locale error fixed

 

 

Conclusion

With these two command lines, you can immediately fix localization errors for Perl-based programs if this error occurs after installing one of the programs or updating a package.

 

Related Content, Useful Links: