Resolve the perl warning 'setting locale failed' problem on Ubuntu Linux

A broken pearl (generated by Midjourney). Credit: libre-software.net. License: CC BY-SA 4.0

Ubuntu: resolve the “perl: warning: Setting locale failed” problem

Last updated on October 11, 2022

Are you running Ubuntu 18.04, 20.04 or 22.04 desktop or server edition, and getting warning or errors when installing software via apt-get or aptitude?

Here is a typical error message:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_TIME = "es_ES.UTF-8",
LC_MONETARY = "de_DE.UTF-8",
LC_ADDRESS = "de_DE.UTF-8",
LC_TELEPHONE = "de_DE.UTF-8",
LC_NAME = "de_DE.UTF-8",
LC_MEASUREMENT = "de_DE.UTF-8",
LC_IDENTIFICATION = "de_DE.UTF-8",
LC_NUMERIC = "de_DE.UTF-8",
LC_PAPER = "de_DE.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

Sometimes, trying to solve the problem using the update-locale or locale commands does not work and generates following error messages:

~ # sudo update-locale
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_PAPER = "de_DE.UTF-8",
LC_ADDRESS = "de_DE.UTF-8",
LC_MONETARY = "de_DE.UTF-8",
LC_NUMERIC = "de_DE.UTF-8",
LC_TELEPHONE = "en_US.UTF-8",
LC_IDENTIFICATION = "en_US.UTF-8",
LC_MEASUREMENT = "en_US.UTF-8",
LC_TIME = "es_ES.UTF-8",
LC_NAME = "de_DE.UTF-8",
LANG = (unset),
are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").

or

~ # locale
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=de_DE.UTF-8
LC_TIME=es_ES.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=de_DE.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=de_DE.UTF-8
LC_NAME=de_DE.UTF-8
LC_ADDRESS=de_DE.UTF-8
LC_TELEPHONE=de_DE.UTF-8
LC_MEASUREMENT=de_DE.UTF-8
LC_IDENTIFICATION=de_DE.UTF-8
LC_ALL=

Solution to the perl locale problem

The solution is to export the missing locales to ~/.bash_profile. The following command is a one-command line:

echo "export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8">>~/.bash_profile

You could also run each command separately:

echo "export LANGUAGE=en_US.UTF-8">>~/.bash_profile

Alternatively, edit ~/.bash_profile “by hand” with nano, vim or a graphical editor like gedit or xed (Linux Mint).

Don’t forget to reboot and check if the new locales are applied with the locale command.

Another solution is to add the locale variables to /etc/environment instead of ~/.bash_profile.

By Johannes Eva, April 2017 – October 2022

Articles by categories

Most Read Articles

Comments

10 thoughts on “AVIF browser test page: AVIF support in Chrome, Firefox, Edge…”

    1. Thank you for your interest – a JPEG XL test page would be useful, but I have no time left at the moment. Hopefully at some time in 2022 🙂

  1. Sadly your site need javascript enable for the test avif vs jpeg. If noscript bloc everything, this page say that AVIF is not supported and display JPEG fallback.
    In JS dependences there is also google-analytics that is not fair play for a libre-software website :(.

    Thank you for your article anyway.

    1. Actually, AVIF/JPEG fallback using the element is pure HTML and does not need Javascript, even on this site. And you’re right, I really should switch from GA to Matomo, it’s a matter of time. Cheers!

  2. Nice article. Love how you included a detailed tutorial for WordPress. I have created a UX optimized converter that support bulk conversion, without the need of uploading files. You can find it on: https://avif.io/

    The next update will include a settings panel on which you can edit the quality, effort and exif data.

    Feel free to add it to the converter list if you feel like it’s a great addition. Sincerely, Justin

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.