Note: Some of the commands below require root privileges, consider the use of
man locale-gen, locales are set in several files.
The main configuration file, which has a simple format: every line that is not empty and does not begin with a # is treated as a locale definition that is to be built.
A directory containing locale.gen snippets provided by language-pack packages. Do not edit these manually, they will be overwritten on package upgrades.
Comprehensive details on locales at the Arch Wiki.
Checking locales and the locale
To check the (already) generated locales, run any of the following commands (with minor output differences).
To check the currently used locale, run any of the following commands (with minor output differences).
Setting and generating (new) locales
Locales are typically set by uncommenting lines in
/etc/locale.gen, after which running
locale-gen is required.
nano /etc/locale.gen # uncomment desired lines (locales)
This will generate locales files for each uncommented line in
/etc/locale.gen (and under
/var/lib/locales/supported.d/), whether they were previously generated or not.
Alternatively, the command
will uncomment the corresponding line in
locale-gen while generating the desired locale and only this one.
To remove locales in
/etc/locale.gen, simply comment the desired lines and regenerate the locales using
locale-gen. The command
locale-gen --purge <locale> doesn't do what the modifier suggests.
To remove locales under
/var/lib/locales/supported.d/ is trickier. Since any file
/var/lib/locales/supported.d/<code> depends on the package
language-pack-<code>-base, any change on the former will be restored when the latter is updated.
Workaround. To prevent changes under
/var/lib/locales/supported.d/, set files in it with the "immutable (i)" attribute. So instead of removing files, empty them. For instance:
rm <code> && touch <code> # <code> has been emptied
lsattr <code> # regular attributes
chattr +i <code> # adding (+) immutable
lsattr <code> # checking attributes
Setting the locale
Setting and generating locales does not set the system locale. Any of the following commands achieves this.
echo LANG=<code> | sudo tee /etc/locale.conf # reboot (might be ignored in Ubuntu)
localectl set-locale LANG=<code>
sudo dpkg-reconfigure locales.