Debian – Can’t generate en_US.UTF-8 Locale

debianlocale

I've been trying to set my locale to en_US.UTF-8 without any success. Based off of other answers around the internet, I should first generate the locale with

sudo locale-gen en_US.UTF-8

And then apply it with

sudo dpkg-reconfigure locales

However, running locale-gen does something weird:

user@Host /home/user $ sudo locale-gen en_US.UTF-8
Generating locales (this might take a while)...
  en_US.ISO-8859-1... done
Generation complete.

As you see, it never actually generates UTF-8, but instead keeps falling back to ISO-8859-1. I can never manage to set LC_ALL to en_US.UTF-8, probably because it can't generate.

Am I doing something wrong? I'm running Debian 8.1.

Best Answer

You've tried to apply a recipe for Ubuntu under Debian. That usually works, but in this specific case it doesn't.

Ubuntu is derived from Debian, and doesn't change much apart from the installer and the GUI. The locale-gen command is one of those few other things that it changes. I don't know why.

Under Debian, the locale-gen command takes no arguments and regenerates the compiled locale definitions according to the configured list of locales. To modify the selection of locales that you want to use, edit the file /etc/locale.gen then run the locale-gen command. Alternatively, run dpkg-reconfigure locales as root, select the additional locales you want (and deselect the ones you don't want), and press OK.

Under Ubuntu, if you run the locale-gen command without arguments, it regenerates the compiled locale definitions according to the configured list of locales. But if you pass some arguments, they're added to the list and generated immediately. The list of locales is kept in /var/lib/locales/supported.d/local. Running dpkg-reconfigure locales just regenerates the compiled locales without giving you an opportunity to modify the selection.

In summary, to add en_US.UTF-8 to the list of usable locales:

  • Debian, interactive: dpkg-reconfigure locales
  • Debian, automated: sed -i 's/^# *\(en_US.UTF-8\)/\1/' /etc/locale.gen && locale-gen
  • Ubuntu, automated: locale-gen en_US.UTF-8