Solution for “Locale Error – perl: warning: Setting locale failed.” [Ubuntu]

We are maintaining old version of Ubuntu servers (10.04 LTS to be specific)

Many times we encounter following errors on terminal:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_CTYPE = "UTF-8",
    LANG = "en_GB.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

Client-Side Solution

This is good option if you manage many servers. Rather than changing every server, pass requested environment.

Open ~/.bash_profile

Add following line:

export LC_ALL=C

Start a new shell or just reload environment using source ~/.bash_profile

Server-Side Solutions

Solution #0

This is new but working nicely.

update-locale LC_ALL=$LANG

Solution #1

export LANGUAGE=en_IN.UTF-8
export LANG=en_IN.UTF-8
export LC_ALL=en_IN.UTF-8
locale-gen en_IN.UTF-8

If for some reason, above failed to work and throws following fresh error:

warning: setlocale: LC_ALL: cannot change locale (en_IN.UTF-8)

Try following alternative solution.

Solution #2

Edit locale file:

vim /etc/default/locale

Add following line:

LC_ALL="en_IN.UTF-8"

Generate locale again:

locale-gen en_IN.UTF-8

Solution #3

Open following file

vim /var/lib/locales/supported.d/local

Make sure it has

en_IN.UTF-8 UTF-8

Then run…

dpkg-reconfigure locales

Test

Run following command:

locale

If you see any error, then that means your issue is not fixed!

Try again. There are some more alternate solutions that you can find on Google.

Above seemed to work for me always. 🙂