Fixing “locales” error on Ubuntu

On a Ubuntu 8.04LTS server, I recently had an annoying case where the system would spew an error out seemingly every time a command was executed.

The error format was thus:
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").
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").

Clearly something wasn’t happy and that something appeared to be my ‘locales‘. They are actually quite self-explanatory, they define the language and location of a user in order to allow the correct presentation of the user interface. Great if you want to avoid having to read Kanji on the command line but not so much use if it’s just Crontab talking to the root account and filling up the mailbox with errors.

With a bit of searching, I found a simple enough answer. Obviously, as the error states, the locales need to be set. To do this issue the command:

sudo locale-gen

You can add your preferred locale to the end of this ie:

sudo locale-gen en_US.UTF-8

…which will generate the US English interface language with UTF-8 character formatting.

Then issue:

sudo dpkg-reconfigure locales

Hopefully, your locales will be set and that annoying error will be banished both from the console and your root inbox.

Credit to this thread at Ubuntu Forums