How to Solve perl: warning: Setting locale failed

February 25, 2020

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.

Need help?

Do you need help setting up this on your own service?
Please contact us and we’ll provide you the best possible quote!