I found, that on my home server, running Ubuntu Server 18.04, I've selected quite a few locales, I actually don't need. I only want en_US.UTF-8 and de_DE.UTF-8, since the whole system is configured to use only these.
So, first, I tried the "Debian way" by running dpkg-reconfigure locales and then deselected all besides the two I actually wanted. After that the system automatically regenerates the locales, but, unfortunately, more than I selected:
Generating locales (this might take a while)...
de_DE.UTF-8... done
en_AG.UTF-8... done
en_AU.UTF-8... done
en_BW.UTF-8... done
en_CA.UTF-8... done
en_DK.UTF-8... done
en_GB.UTF-8... done
en_HK.UTF-8... done
en_IE.UTF-8... done
en_IL.UTF-8... done
en_IN.UTF-8... done
en_NG.UTF-8... done
en_NZ.UTF-8... done
en_PH.UTF-8... done
en_SG.UTF-8... done
en_US.UTF-8... done
en_ZA.UTF-8... done
en_ZM.UTF-8... done
en_ZW.UTF-8... doneThen I tried directly editing /etc/locale.gen, but it's all fine in there, since only the two I actually want are not commented out, so it should work. I've checked the file multiple times from top to bottom.
Still, running locale-gen manually, yields the same result as above.
So I wonder if this is a bug or a feature? Is the file maybe cached somewhere or is there another configuration file I'm not aware of? I've already tried restarting the system, but as expected, this didn't change anything.
2 Answers
The many English locales are probably there because you installed the English language packs. You should see them by running:
cat /var/lib/locales/supported.d/enSo a way to make the list shorter is to remove the English language packs:
sudo apt purge language-pack-en language-pack-en-base language-pack-gnome-en language-pack-gnome-en-base 6 I found a solution that works in my case, that I find more complete than the accepted answer.
If I edit my locales editing file /etc/locale.gen or selecting them with command dpkg-reconfigure locales, when I select any locale of a language I got locales for all the variants of this language. Example, if I select only en_US.UTF-8, I got this list:
en_AG
en_AG.utf8
en_AU.utf8
en_BW.utf8
en_CA.utf8
en_DK.utf8
en_GB.utf8
en_HK.utf8
en_IE.utf8
en_IL
en_IL.utf8
en_IN
en_IN.utf8
en_NG
en_NG.utf8
en_NZ.utf8
en_PH.utf8
en_SG.utf8
en_US.utf8
en_ZA.utf8
en_ZM
en_ZM.utf8
en_ZW.utf8Which obviously is not what I want.
My solution:After selecting my preferred locales with previous commands, I edit the specific language file in /var/lib/locales/supported.d/. In my example, I edit file /var/lib/locales/supported.d/en, which contains the complete list of locales I showed previously. I leave only this line:
en_US.UTF-8 UTF-8Then I execute the command sudo dpkg-reconfigure locales -f noninteractive and I got only my preferred locales, not all the variants I don't want. This works with multiple languages, and I feel so useful with the ones with many variants (Spanish, English, etc.).
I hope this helps others in this situation like me.
Tested in Ubuntu server 18.04 and 20.04.
2