michiel
By:
michiel

Fixing the locale issue in a clean DigitalOcean droplet

February 21, 2014 21.4k views
I've read numerous posts about people having problems with the default locale on a clean Digital Ocean droplet with Ubuntu. This manifests in getting errors like: bash: warning: setlocale: LC_ALL: cannot change locale (en_US) There is a quick fix, which is just running locale-gen en_US But. Can't this be fixed in the default Ubuntu image? Apparently en_US is installed as the default locale, but the locale files aren't generated. Am I thinking too simple? Are there any reasons why this can't be included in the default image? Thanks!
1 comment
16 Answers
this works for me:

edit the file
/etc/environment

add one line with your LANG, like this

LC_ALL="en_US.UTF-8"

save and reboot

Are you sure running the following commands doesn't fix it?
sudo locale-gen en_US.UTF-8

sudo dpkg-reconfigure locales
What exact image are you using?
Just create a new droplet with the default ubuntu (12.04.3 x64) and then when you login with the console via ssh and type locale there's an error about this. I can't seem to fix this with running locale-gen en_US or whatever "fix" I could find on StackOverflow or the Ubuntu pages.
Can you post the exact error?
locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE=UTF-8
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
..and you will see errors like this when you try to set stuff or when an app wants to do something like a set locale.

~# sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password root"
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_CTYPE = "UTF-8",
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Err.. Short reply

Thanks juanluis, that fixed it for me :)
The commands from Kamal didn't help at all :/

juanluis, thanks this worked. Just have to remember to reboot before do anything.

What ceases to amaze me is how DO can put out stuff in prime time wasting everyones time with such an idiotic problem, there are posts all over the place and such a simple fix. Bad first hour on DO suffice to say ;(

I just had the same problem on a fresh droplet. The solution worked, however it's a bit weird that the linux images are not preconfigured correctly with working locale settings.

@juanluis That works for me as well on One-Click WordPress setup. Cheers.

Please try this

sudo nano /etc/default/locale

and edit the contet to be like that:
LANGUAGE=enUS.UTF-8
LC
ALL=enUS.UTF-8
LANG=en
US.UTF-8
LCTYPE=enUS.UTF-8

It works for me.

Cheers,
Ruslan

It is now 2016 and this problem is still not fixed.
Everytime I have to test something and I spin up a Debian or Ubuntu server I ran into this problem.
Until I realized it and then fixed it I wasted so much time that all those proposed speed advantages of DO are gone anyway.
Currently it looks like this:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_PAPER = "de_CH.UTF-8",
    LC_ADDRESS = "de_CH.UTF-8",
    LC_MONETARY = "de_CH.UTF-8",
    LC_NUMERIC = "de_CH.UTF-8",
    LC_TELEPHONE = "de_CH.UTF-8",
    LC_IDENTIFICATION = "de_CH.UTF-8",
    LC_MEASUREMENT = "de_CH.UTF-8",
    LC_TIME = "de_CH.UTF-8",
    LC_NAME = "de_CH.UTF-8",
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").

What are those crap entries doing in a fresh droplet?

It is now 2017 and this problem is still not fixed.

export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

Then run

sudo update-locale

Now run

locale

you shouldn't see any errors.

For a permanent solution,
Add the above export commands inside ~/.profile

Have another answer? Share your knowledge.