showkey Asked: 2015-10-10 05:44:44 +0800 CST2015-10-10 05:44:44 +0800 CST 2015-10-10 05:44:44 +0800 CST How to automate 'dpkg-reconfigure locales' with one command? 772 In the console to input dpkg-reconfigure locales,a gui jump out ,i select en_HK.UTF-8 as my target ,click enter. dpkg-reconfigure locales Generating locales (this might take a while)... en_HK.UTF-8... done How to automate the whole process into one command ? locale 6 Answers Voted David Tabernero M. 2018-04-22T12:41:31+08:002018-04-22T12:41:31+08:00 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. T-Dawg 2020-06-04T14:28:11+08:002020-06-04T14:28:11+08:00 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 Best Answer TellMeWhy 2015-10-10T05:56:05+08:002015-10-10T05:56:05+08:00 One command: sudo update-locale LANG=en_HK.UTF-8 Easy day :) Gunnar Hjalmarsson 2015-10-10T07:58:08+08:002015-10-10T07:58:08+08:00 I would probably run: sudo locale-gen --purge That regenerates all the locales for your installed languages. Redzarf 2018-02-08T10:18:36+08:002018-02-08T10:18:36+08:00 This gist had the solution for me: sudo sed -i '/^#.* en_US.* /s/^#//' /etc/locale.gen sudo locale-gen Philippe Cloutier 2021-01-15T15:24:44+08:002021-01-15T15:24:44+08:00 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
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:
Another possibility (that works even better) is through the
debconf-utils
utilities anddebconf-set-selections
(run as root):Hope this might help.
I would suggest:
or if it absolutely has to be "one command":
For an explanation see my answer at https://askubuntu.com/a/1246655/912933
One command:
Easy day :)
I would probably run:
That regenerates all the locales for your installed languages.
This gist had the solution for me:
If you want to generate a single locale, this should theoretically suffice:
In practice though, dpkg-reconfigure will fail to generate the locale under Ubuntu 20.04. To workaround, you need an additional command: