How to fix locale: Cannot set LC_ALL to default locale: No such file or directory in APT
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- Quick fix: Set LC_ALL to C (minimal locale)
- Permanent fix: Install and generate locales
- Using dpkg-reconfigure (Debian/Ubuntu)
- For Docker containers: Set locale in Dockerfile
export LC_ALL=Cexport LANG=Clocale: 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
- 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
- Docker image or container lacks locale data
- 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"
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.
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
- ๐APT Official Documentation
- ๐Debian Wiki: Locale(Official Docs)
- ๐Baeldung: Locale Environment Variables in Linux(Official Docs)