locale-gen Command on Debian
01.05.2026
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:
For closely related localization / encoding topics, see mb_detect_encoding in PHP — Detect Character Encoding and DB_COLLATE in WordPress — What It Is and How It Works.
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-genandsudo 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


