How to Solve perl: warning: Setting locale failed

Today, on my ubuntu server I executed the following command to reconfigure MariaDB server.

sudo dpkg-reconfigure mariadb-server-10.0

A warning appeared on the screen.

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
 LANGUAGE = "en_HK:en",
 LC_ALL = (unset),
 LC_PAPER = "zh_CN.UTF-8",
 LC_ADDRESS = "zh_CN.UTF-8",
 LC_MONETARY = "zh_CN.UTF-8",
 LC_NUMERIC = "zh_CN.UTF-8",
 LC_TELEPHONE = "zh_CN.UTF-8",
 LC_IDENTIFICATION = "zh_CN.UTF-8",
 LC_MEASUREMENT = "zh_CN.UTF-8",
 LC_TIME = "zh_CN.UTF-8",
 LC_NAME = "zh_CN.UTF-8",
 LANG = "en_HK.UTF-8"
 are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_HK.UTF-8").
locale: Cannot set LC_ALL to default locale: No such file or directory

It says setting locale failed.

The Solution

First list the current locale settings for the user.

$ locale
LANG=en_HK.UTF-8
LANGUAGE=en_HK:en
LC_CTYPE="en_HK.UTF-8"
LC_NUMERIC=zh_CN.UTF-8
LC_TIME=zh_CN.UTF-8
LC_COLLATE="en_HK.UTF-8"
LC_MONETARY=zh_CN.UTF-8
LC_MESSAGES="en_HK.UTF-8"
LC_PAPER=zh_CN.UTF-8
LC_NAME=zh_CN.UTF-8
LC_ADDRESS=zh_CN.UTF-8
LC_TELEPHONE=zh_CN.UTF-8
LC_MEASUREMENT=zh_CN.UTF-8
LC_IDENTIFICATION=zh_CN.UTF-8
LC_ALL=

Then generate these locales one by one.

$ sudo locale-gen "en_HK.UTF-8"
Generating locales...
 en_HK.UTF-8... up-to-date
Generation complete.
$ sudo locale-gen "zh_CN.UTF-8"
Generating locales...
 zh_CN.UTF-8... done
Generation complete.

Finally reconfigure locales.

$ sudo dpkg-reconfigure locales
Generating locales...
 en_HK.UTF-8... done
 en_US.UTF-8... done
 zh_CN.UTF-8... up-to-date
Generation complete.

Now the locale issue is gone.

Rate this tutorial
[Total: 4 Average: 4.8]

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here