Ubuntu – Fix stubborn ‘Setting locale failed.’

localizationUbuntu

I have a very stubborn, well-known locale error on Ubuntu 9.10:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_TIME = "custom.UTF-8",
    LANG = "en_US.UTF-8"

Tried the following:

  • Added LANG=en_US.UTF-8 and LC_ALL=en_US.UTF-8 to /etc/environment
  • Run apt-get install --reinstall locales (error: perl: warning: Falling back to the standard locale ("C"). /usr/bin/mandb: can't set the locale; make sure $LC_* and $LANG are correct)
  • Run sudo dpkg-reconfigure locales. Result: Cannot set LC_ALL to default locale: No such file or directory, and then updates locales all locales including en_US.UTF-8
  • sudo locale-gen updates all locales successfully, including en_US.UTF-8
  • sudo locale-gen un_US en_US.UTF-8 gives no error nor other output
  • In /etc/default/locale it says LANG="en_US.UTF-8"
  • echo $LANG gives en_US.UTF-8
  • /var/lib/locales/supported.d/local says en_US.UTF-8 UTF-8
  • locale -a gives me:
C
en_AG
en_AU.utf8
en_BW.utf8
en_CA.utf8
en_DK.utf8
en_GB.utf8
en_HK.utf8
en_IE.utf8
en_IN
en_NG
en_NZ.utf8
en_PH.utf8
en_SG.utf8
en_US.utf8
en_ZA.utf8
en_ZW.utf8
POSIX

So well… I am pretty much out of options I can think of. Anybody any idea??

Thanks!

Best Answer

Had the same problem and found the solution. You have to recreate the custom.UTF-8 locale def (the "custom" file is probably there because you changed the date or time format). Run

sudo localedef -f UTF-8 -i custom custom.UTF-8

Another way to do this is to add the locale to the ones you want dpkg-reconfigure locales to configure for you. On Debian:

echo 'custom.UTF-8 UTF-8' |sudo tee -a /etc/locale.gen
sudo dpkg-reconfigure locales

On Ubuntu:

echo 'custom.UTF-8 UTF-8' |sudo tee -a /var/lib/locales/supported.d/local
sudo dpkg-reconfigure locales

Hope this helps!