Era Host hosting
EraHost – Free Domain, Cheap Hosting!
Client Area
Support 24/7
Menu

locale-gen Command on Debian

2 min read
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.
Linux VDS
High performance for your projects
  • Root access and flexible setup
  • Control panel
  • NVMe disks
  • DDR5
Linux VDS

How to Use locale-gen on Debian

Check Current Locale

Run the following command to see the current system locale:

locale-gen Debian Command Guide
locale-gen — Debian/Ubuntu way to compile locale data.

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

  1. Edit the locale configuration file:
    sudo nano /etc/locale.gen
  2. Uncomment (remove #) the locales you want to generate. For example:
    en_US.UTF-8 UTF-8
    en_GB.UTF-8 UTF-8
  3. 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:

  1. Run:
    sudo update-locale LANG=en_US.UTF-8

    Replace en_US.UTF-8 with your desired locale.

  2. Verify the settings:
    locale

Troubleshooting Locale Issues

Missing Locale Error

  • Error: locale: Cannot set LC_ALL to default locale
  • Fix:
    1. Ensure the desired locale is uncommented in /etc/locale.gen.
    2. Run sudo locale-gen and sudo update-locale.

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 ~/.bashrc for persistence.

Verify Available Locales

List all generated locales:

locale -a

Frequently asked questions
Your SSH client forwards locale env vars (LANG, LC_*) to the server. If your local system uses `en_US.UTF-8` and the server doesn't have that locale compiled, Perl/Bash/many tools complain. Two fixes: (1) generate the missing locale on the server (`locale-gen en_US.UTF-8`), or (2) tell SSH not to forward locale: remove `SendEnv LANG LC_*` from your `/etc/ssh/ssh_config`.
locale-gen only generates locales uncommented in `/etc/locale.gen`. If you call `locale-gen en_GB.UTF-8` but `en_GB.UTF-8` isn't enabled in locale.gen, nothing happens. Either uncomment the line and run `locale-gen`, or use `dpkg-reconfigure locales` for an interactive UI.
Slim Debian/Ubuntu images strip the `locales` package. `apt install -y locales` first, then `locale-gen en_US.UTF-8`, then `update-locale LANG=en_US.UTF-8`. Or simpler: use `C.UTF-8` (always available on glibc-based systems, no generation needed). For most containers, C.UTF-8 is the right choice.
LANG is the default for all LC_* categories. LC_ALL overrides everything (highest precedence). Individual LC_* (LC_CTYPE, LC_TIME, LC_NUMERIC, etc.) override LANG for that one category. Common setup: `LANG=en_US.UTF-8` globally, LC_ALL unset, override LC_TIME=de_DE.UTF-8 if you want German date formatting. Setting LC_ALL is often a workaround that masks real locale config bugs.
Related articles
KVM "Virgin" Files — Setting Up a Clean KVM Virtual Machine
Understanding the .cagefs Folder in CloudLinux (cPanel Hosting)
Revisium Antivirus Overview: Complete Website Security Solution