Debian commands can show locale warnings, sort text unexpectedly, or format dates and currency in the wrong regional style when the requested locale has not been generated on the host. Generating the locale compiles the language and character-set data that programs need before a user, service, or system default can use values such as en_GB.UTF-8.
The locales package provides locale-gen and the locale templates used by glibc. The file /etc/locale.gen lists which locale and character-set pairs should be built, and locale-gen compiles the selected entries into the system locale archive.
Use UTF-8 locales unless a legacy application requires another character set. Generating a locale makes it available to the system, but existing shells and services keep their current LANG and LC_* values until they are restarted or started in a new login session.
$ locale -a C C.utf8 POSIX
If the target locale already appears in this list, the locale data has already been generated. A generated en_GB.UTF-8 locale is normally listed by locale -a as en_GB.utf8.
$ sudo apt install locales Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: libc-l10n The following NEW packages will be installed: libc-l10n locales ##### snipped ##### Setting up locales (2.41-12+deb13u3) ... Generating locales (this might take a while)... Generation complete.
Minimal containers and trimmed server images may not include locale-gen until the locales package is installed. Full Debian installations often already have it.
$ grep -F 'en_GB.UTF-8' /usr/share/i18n/SUPPORTED en_GB.UTF-8 UTF-8
Replace en_GB.UTF-8 with the language and region needed on the host. Keep the two-field form from the supported list when editing /etc/locale.gen.
$ sudo cp /etc/locale.gen /etc/locale.gen.bak
$ sudo editor /etc/locale.gen
Uncomment the target line by removing the leading #, or add the exact supported line if it is missing.
en_GB.UTF-8 UTF-8
Leave other uncommented locales in place if they are still needed. Commenting a line and running locale-gen again removes that locale from the generated archive.
$ sudo locale-gen Generating locales (this might take a while)... en_GB.UTF-8... done Generation complete.
locale-gen reads every uncommented entry in /etc/locale.gen. The output should include the locale just enabled and end with Generation complete.
$ locale -a C C.utf8 POSIX en_GB.utf8
The lowercase utf8 suffix in locale -a output is expected. It still matches the UTF-8 locale generated from /etc/locale.gen.
$ sudo update-locale LANG=en_GB.UTF-8
Skip this step when the locale is only needed by a single service, script, or user profile. Set that service or shell environment directly instead.
$ cat /etc/locale.conf # File generated by update-locale LANG=en_GB.UTF-8
On current Debian systems, update-locale writes /etc/locale.conf. Existing login shells do not reread the file until the session is restarted.