16

In the console to input dpkg-reconfigure locales,a gui jump out ,i select en_HK.UTF-8 as my target ,click enter.

enter image description here

dpkg-reconfigure locales
Generating locales (this might take a while)...
en_HK.UTF-8... done

How to automate the whole process into one command ?

1
4

One command:

sudo update-locale LANG=en_HK.UTF-8

Easy day :)

1
  • 3
    update-locale is for updating /etc/default/locale. In other words it's something else... Oct 9 '15 at 16:00
8

What worked charm for me was a combination between the @DevRobot's and the @Gunnar Hjalmarsson's answers (run as root). EDIT: Added some improvements to avoid annoying errors:

update-locale "LANG=en_HK.UTF-8"
locale-gen --purge "en_HK.UTF-8"
dpkg-reconfigure --frontend noninteractive locales

Another possibility (that works even better) is through the debconf-utils utilities and debconf-set-selections (run as root):

echo "locales locales/default_environment_locale select en_HK.UTF-8" | debconf-set-selections
echo "locales locales/locales_to_be_generated multiselect en_HK.UTF-8 UTF-8" | debconf-set-selections
rm "/etc/locale.gen"
dpkg-reconfigure --frontend noninteractive locales

Hope this might help.

5

I would suggest:

echo "en_HK.UTF-8" | sudo tee -a /etc/locale.gen
sudo locale-gen

or if it absolutely has to be "one command":

echo "en_HK.UTF-8" | sudo tee -a /etc/locale.gen; sudo locale-gen

For an explanation see my answer at https://askubuntu.com/a/1246655/912933

1

I would probably run:

sudo locale-gen --purge

That regenerates all the locales for your installed languages.

1

This gist had the solution for me:

sudo sed -i '/^#.* en_US.* /s/^#//' /etc/locale.gen
sudo locale-gen
0

If you want to generate a single locale, this should theoretically suffice:

echo "locales locales/locales_to_be_generated multiselect en_HK.UTF-8 UTF-8" | debconf-set-selections
dpkg-reconfigure --frontend noninteractive locales

In practice though, dpkg-reconfigure will fail to generate the locale under Ubuntu 20.04. To workaround, you need an additional command:

echo "locales locales/locales_to_be_generated multiselect en_HK.UTF-8 UTF-8" | debconf-set-selections
rm /etc/locale.gen
dpkg-reconfigure --frontend noninteractive locales

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.