How to fix locale: Cannot set LC_ALL to default locale: No such file or directory in APT

APTBEGINNERMEDIUMUpdated Sep 9, 2026ยท 357 views

This error occurs when your system tries to use a locale that hasn't been generated or installed. It's common in minimal Debian/Ubuntu installations or Docker containers. Fix it by generating the missing locale or setting a default.

Quick fix

Fixes locale: Cannot set LC_ALL to default locale: No such file or directory

export LC_ALL=C
export LANG=C
  1. Quick fix: Set LC_ALL to C (minimal locale)
  2. Permanent fix: Install and generate locales
  3. Using dpkg-reconfigure (Debian/Ubuntu)
  4. For Docker containers: Set locale in Dockerfile
apt โ€” error
export LC_ALL=C
export LANG=C
locale: Cannot set LC_ALL to default locale: No such file or directory

What this error means

The locale system on Linux uses environment variables (LANG, LC_ALL, etc.) to control how text, dates, numbers, and currency are displayed. When a process tries to set LC_ALL to a locale that doesn't exist on the system, it fails with this error. This commonly happens in: - Minimal Docker images or cloud instances - Fresh system installations - When SSH sessions inherit locale variables from the client - After system upgrades that removed locale data The error prevents package installation scripts and system utilities from running properly, blocking critical operations like apt installations.

Typical symptoms

  • apt or dpkg commands fail with locale warnings
  • Package installation hangs or fails mid-process
  • Perl scripts emit warnings about locale settings
  • Automated deployment scripts fail silently
  • SSH sessions show locale warnings on login

Common causes

  1. The system is set to use a locale (e.g., en_US.UTF-8) that hasn't been generated in /usr/share/locales
  2. Locale packages are missing or not fully installed
  3. SSH client sends locale variables that don't exist on the server
  4. Docker image or container lacks locale data
  5. LC_ALL environment variable is set to an invalid value

How to fix "locale: Cannot set LC_ALL to default locale: No such file or directory"

1Quick fix: Set LC_ALL to C (minimal locale)

Export LC_ALL to the C locale, which is always available:

bash
export LC_ALL=C
export LANG=C

This allows operations to proceed. To make it permanent for your user, add these lines to ~/.bashrc or ~/.profile.

2Permanent fix: Install and generate locales

First, ensure the locales package is installed:

bash
sudo apt-get update
sudo apt-get install -y locales

Then generate the en_US.UTF-8 locale:

bash
sudo locale-gen en_US.UTF-8

Update your system locale settings:

bash
sudo update-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8

Verify the locale was generated:

bash
locale -a | grep en_US
3Using dpkg-reconfigure (Debian/Ubuntu)

Use the interactive locale configuration tool:

bash
sudo dpkg-reconfigure locales

In the menu:
1. Check the box next to en_US.UTF-8 (or your preferred locale)
2. Press Space to select, Tab to navigate
3. Select the locale as your default when prompted
4. Press Enter to apply

For servers, choosing "None" as default is often recommended to avoid locale mismatches with remote clients.

4For Docker containers: Set locale in Dockerfile

Add these lines to your Dockerfile to prevent locale issues:

dockerfile
# Install locale support
RUN apt-get update && apt-get install -y locales && \
    locale-gen en_US.UTF-8 && \
    update-locale LANG=en_US.UTF-8

# Set environment variables
ENV LANG=en_US.UTF-8
ENV LC_ALL=en_US.UTF-8
ENV LC_CTYPE=en_US.UTF-8

Or for minimal images, just set LC_ALL to C:

dockerfile
ENV LC_ALL=C
ENV LANG=C
5Verify locale configuration

After applying fixes, verify your locale settings:

bash
locale

You should see output without warnings. If you still see locale-related warnings, check that your SSH client isn't sending locale variables:

bash
# On the remote system, check what LC_ALL is set to
echo $LC_ALL
echo $LANG

If they're empty or set to C, locale is correctly configured.

Advanced notes

LC_ALL vs LANG: LC_ALL overrides all other locale variables and should be used sparingly (mainly for testing/scripts). For permanent fixes, set LANG instead, which applies to all LC_* categories unless overridden individually.

In Docker: Minimal base images (alpine, scratch) don't include locale data by default. For these, using LC_ALL=C is the standard approach rather than attempting to generate locales.

SSH Locale Inheritance: When you SSH into a server, your client may send locale variables (SendEnv LANG LC_* in ~/.ssh/config). If the server doesn't have those locales, you'll see this error. Either configure the server with those locales or disable locale forwarding on the client.

Performance Note: Generating all locales with 'locale-gen' is slow. For production, generate only the locales you need.

Frequently asked questions

What does "locale: Cannot set LC_ALL to default locale: No such file or directory" mean?
) to control how text, dates, numbers, and currency are displayed. When a process tries to set LC_ALL to a locale that doesn't exist on the system, it fails with this error. This commonly happens in: - Minimal Docker images or cloud instances - Fresh system installations - When SSH sessions inherit locale variables from the client - After system upgrades that removed locale data The error prevents package installation scripts and system utilities from running properly, blocking critical operations like apt installations.
How do I fix "locale: Cannot set LC_ALL to default locale: No such file or directory"?
This error occurs when your system tries to use a locale that hasn't been generated or installed. It's common in minimal Debian/Ubuntu installations or Docker containers. Fix it by generating the missing locale or setting a default.
What causes "locale: Cannot set LC_ALL to default locale: No such file or directory"?
The system is set to use a locale (e.g., en_US.UTF-8) that hasn't been generated in /usr/share/locales Locale packages are missing or not fully installed SSH client sends locale variables that don't exist on the server
Is the "locale: Cannot set LC_ALL to default locale: No such file or directory" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading