How to solve LOCALE problem [duplicate]

I am facing a problem as asked in this question, I have tried the proposed solution but facing the same issue

When I run locale,

locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES 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=en_US.UTF-8
LC_CTYPE="en_US.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=en_US.UTF-8

When I run

sudo locale-gen en_US.UTF-8

I get this error

sudo: unable to resolve host ubuntu
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
Generating locales...
en_US.UTF-8... /usr/sbin/locale-gen: line 177: warning: setlocale: 
LC_ALL: cannot change locale (en_US.UTF-8)
/usr/sbin/locale-gen: line 243: 
8925 Killed localedef $no_archive -i $input -c -f $charset $locale_alias
$locale failed
Generation complete.

I am running Ubuntu Cloud Image on OpenStack cloud


Solution 1:

The problem is due to this bug. The cloud images only support "en_US.UTF-8" so you have to make sure that the host server (the install of Ubuntu Server which you use to SSH into the cloud install) is configured to use "en_US.UTF-8"

To do this generate the "en_US.UTF-8" on the Ubuntu server install:

$ sudo locale-gen en_US.UTF-8
Generating locales...
  en_US.UTF-8... done
Generation complete.

$ sudo dpkg-reconfigure locales
Generating locales...
  en_US.UTF-8... done
Generation complete.

Use the newly generated locale on the Ubuntu Server install by editing /etc/default/locale to contain only this line:

LANG=en_US.UTF-8

Reboot and then access the cloud install.

Edit:

People with a similar problem have had good luck editing (or creating) /etc/environment to contain:

LANG=en_US.UTF-8

... as well.