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.
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.
Export LC_ALL to the C locale, which is always available:
export LC_ALL=C
export LANG=CThis allows operations to proceed. To make it permanent for your user, add these lines to ~/.bashrc or ~/.profile.
First, ensure the locales package is installed:
sudo apt-get update
sudo apt-get install -y localesThen generate the en_US.UTF-8 locale:
sudo locale-gen en_US.UTF-8Update your system locale settings:
sudo update-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8Verify the locale was generated:
locale -a | grep en_USUse the interactive locale configuration tool:
sudo dpkg-reconfigure localesIn 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.
Add these lines to your Dockerfile to prevent locale issues:
# 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-8Or for minimal images, just set LC_ALL to C:
ENV LC_ALL=C
ENV LANG=CAfter applying fixes, verify your locale settings:
localeYou should see output without warnings. If you still see locale-related warnings, check that your SSH client isn't sending locale variables:
# On the remote system, check what LC_ALL is set to
echo $LC_ALL
echo $LANGIf they're empty or set to C, locale is correctly configured.
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.
E: Could not connect to proxy server
Could not connect to proxy server
E: Package 'package:i386' has no installation candidate
How to fix "Package package:i386 has no installation candidate" in apt
E: The value 'value' is invalid for APT::Default-Release
How to fix invalid APT::Default-Release value in APT
dpkg: error: unable to create new file 'path': Permission denied
How to fix dpkg permission denied errors in APT
subprocess installed post-removal script returned error exit status 1
How to fix "subprocess installed post-removal script returned error exit status 1" in APT