How to solve “Falling back to the standard locale” in Ubuntu

ubuntuSometimes you may get an error like this:

perl: warning: Setting locale failed.

perl: warning: Please check that your locale settings:

LANGUAGE = (unset),

LC_ALL = (unset),

LC_PAPER = “pt_BR.UTF-8”,

LC_ADDRESS = “pt_BR.UTF-8”,

LC_MONETARY = “pt_BR.UTF-8”,

LC_NUMERIC = “pt_BR.UTF-8”,

LC_TELEPHONE = “pt_BR.UTF-8”,

LC_IDENTIFICATION = “pt_BR.UTF-8”,

LC_MEASUREMENT = “pt_BR.UTF-8”,

LC_TIME = “pt_BR.UTF-8”,

LC_NAME = “pt_BR.UTF-8”,

LANG = “en_US.UTF-8”

are supported and installed on your system.

perl: warning: Falling back to the standard locale (“C”).

Click Continue reading to see how to fix this!

Generate the missing UTF-8 locales and set a consistent system-wide default:

sudo locale-gen en_US.UTF-8 pt_BR.UTF-8
sudo update-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8
sudo dpkg-reconfigure locales

Why this often happens over SSH: Local SSH clients commonly forward workstation environment variables (SendEnv LANG LC_* in /etc/ssh/ssh_config). When connecting from a desktop configured with pt_BR.UTF-8 into a fresh cloud VM that only generated en_US.UTF-8, Perl and apt immediately warn about the missing locale. Generating both locales on the server (or disabling AcceptEnv LANG LC_* on test hosts) fixes the warning.

Comments are Disabled