The locale-gen command is used in Debian-based Linux distributions to generate and configure system locales. A locale defines regional settings such as language, time format, currency format, and character encoding.
Locales are essential for proper localization of applications, including date/time formats, number formatting, and character encoding.
What is locale-gen?
- Purpose: Generates the necessary locale data for the system to support specific languages and regional settings.
- Common Use Cases:
- Fixing issues where a locale is not found or improperly set.
- Setting up language support for applications.
How to Use locale-gen on Debian
Check Current Locale
Run the following command to see the current system locale:
locale
If you see errors like locale: Cannot set LC_ALL to default locale, you need to configure or generate the locale.
Configure Locales
- Edit the locale configuration file:
sudo nano /etc/locale.gen - Uncomment (remove
#) the locales you want to generate. For example:en_US.UTF-8 UTF-8 en_GB.UTF-8 UTF-8 - Save and exit the file.
Generate the Locales
Run the locale-gen command to generate the selected locales:
sudo locale-gen
Set the Default Locale
To set the system-wide default locale:
- Run:
sudo update-locale LANG=en_US.UTF-8Replace
en_US.UTF-8with your desired locale. - Verify the settings:
locale
Troubleshooting Locale Issues
Missing Locale Error
- Error:
locale: Cannot set LC_ALL to default locale - Fix:
- Ensure the desired locale is uncommented in
/etc/locale.gen. - Run sudo locale-gen and sudo update-locale.
- Ensure the desired locale is uncommented in
Applications Displaying Wrong Language
- Set the language environment variable:
export LANG=en_US.UTF-8 export LANGUAGE=en_US.UTF-8 export LC_ALL=en_US.UTF-8 - Add these lines to
~/.bashrcfor persistence.
Verify Available Locales
List all generated locales:
locale -a


