locale-gen
Generate system locale files
TLDR
Generate locales
Do not delete undefined locales
SYNOPSIS
locale-gen [OPTION...] [LOCALE...]
PARAMETERS
LOCALE...
Specifies one or more specific locale names (e.g., en_US.UTF-8) to generate, overriding the list in /etc/locale.gen if provided.
--purge
Removes all previously generated locale data that is not explicitly requested in /etc/locale.gen or via command-line arguments.
--no-purge
Prevents the removal of any existing locale data. This is often the default behavior.
--gen-archive
Forces regeneration of the primary locale archive (e.g., /usr/lib/locale/locale-archive) from individual locale files, even if no new locales are generated.
--list
Lists all available locale names that can be generated on the system.
--help
Displays a help message and exits.
--version
Shows version information and exits.
DESCRIPTION
locale-gen is a crucial utility that compiles and generates system-wide locale data, which is essential for proper internationalization (i18n) on Linux systems.
Applications rely on these compiled locales to correctly display language-specific information, including character sets, currency formats, date and time representations, sorting rules, and numeric separators. By default, locale-gen reads the /etc/locale.gen configuration file, which lists the desired locales to be generated (e.g., en_US.UTF-8, de_DE.UTF-8).
Upon execution, it processes the textual locale definitions found in directories like /usr/share/i18n/locales and creates binary locale archives or individual locale files, typically consolidated into /usr/lib/locale/locale-archive. This optimization significantly speeds up locale lookup by applications.
While often invoked automatically during system updates or through tools like dpkg-reconfigure locales on Debian-based systems, direct invocation allows administrators to generate specific locales or manage the installed set of locales manually.
CAVEATS
locale-gen typically requires root privileges to execute because it modifies system-wide files.
Changes to /etc/locale.gen do not take effect until locale-gen is run. Generating a large number of locales can consume significant disk space and increase system boot time or initial application loading times.
The generated locales affect system-wide settings; individual users might still need to configure their environment variables (e.g., LANG, LC_ALL) to utilize specific locales.
CONFIGURATION FILE
The primary configuration for locale-gen is the file /etc/locale.gen. This file contains a list of locale definitions, usually commented out. Uncommenting a line tells locale-gen to generate that specific locale when it is run without arguments. Each entry typically includes the locale name and its character encoding (e.g., en_US.UTF-8).
OUTPUT LOCATION
Generated locale data is usually stored in a consolidated locale archive, most commonly at /usr/lib/locale/locale-archive. In some configurations, individual locale files might be placed directly in /usr/lib/locale/ directories. Applications consult this archive or these files to obtain locale-specific data.
HISTORY
locale-gen is an integral part of the GNU C Library (glibc) distribution, which provides fundamental routines for all Linux programs. Its functionality has been crucial since the early days of Linux to enable broad internationalization support. The command's primary role is to efficiently compile human-readable locale definitions into optimized binary formats, a process that has remained largely consistent over its development, adapting to evolving locale standards and character encodings like UTF-8.