Ad Space — Top Banner

Locale Error

Linux Linux

Severity: Minor

What Does This Error Mean?

Linux locale errors appear when the system's language and regional settings are not properly configured or the locale data is missing. You might see messages like 'locale: Cannot set LC_ALL to default locale: No such file or directory' or 'warning: setlocale: LC_ALL: cannot change locale.' This is common on fresh server installations, Docker containers, and systems connected to via SSH.

Affected Models

  • Ubuntu
  • Debian
  • Fedora
  • CentOS
  • Arch Linux
  • Raspberry Pi OS

Common Causes

  • The locale specified in environment variables is not installed on the system
  • The locale was not generated after the package was installed
  • Connecting via SSH passed locale settings from your local machine that the server does not have
  • A minimal installation skipped locale generation to save space
  • The /etc/locale.gen file has the required locale commented out

How to Fix It

  1. Check which locales are installed. Run: locale -a to list all installed locales. Run: locale to see your current locale settings.

    If the locale shown in your settings (e.g., en_US.UTF-8) is not in the locale -a list, it needs to be generated.

  2. Generate the locale (Ubuntu/Debian). Run: sudo locale-gen en_US.UTF-8 (replace with your locale). Then: sudo update-locale LANG=en_US.UTF-8

    locale-gen compiles the locale data from the definitions installed with the locales package.

  3. Generate locales using dpkg-reconfigure. Run: sudo dpkg-reconfigure locales. A dialog appears — select the locales you need and choose a default.

    This is the most user-friendly way to manage locales on Debian/Ubuntu systems.

  4. Fix SSH locale forwarding. Edit /etc/ssh/sshd_config on the server and comment out or remove the line: AcceptEnv LANG LC_*. Restart SSH: sudo systemctl restart sshd.

    This stops the server from accepting locale settings from SSH clients. The server then uses its own configured locale instead.

  5. Set a valid locale in your shell config. Add to ~/.bashrc or ~/.profile: export LANG=en_US.UTF-8 and export LC_ALL=en_US.UTF-8. Run: source ~/.bashrc to apply.

    Setting these variables explicitly in your shell config ensures a valid locale is always set, regardless of what the system defaults are.

When to Call a Professional

Locale errors are completely harmless to your data and always fixable with a few commands. You should never need professional help for a locale error. If locale errors appear in many programs after an update, regenerating locales fixes them all.

Frequently Asked Questions

What is a locale on Linux?

A locale is a set of settings that control how the system displays language, numbers, dates, and currency. For example, en_US.UTF-8 means English language, United States conventions, UTF-8 character encoding. UTF-8 is important — it supports all characters from all languages and is the modern standard.

Will locale errors break my programs?

Usually not — most programs fall back to the C or POSIX locale if their preferred locale is unavailable. You might see warning messages but programs typically still work. However, programs that handle international text, special characters, or date formatting may behave incorrectly.

I fixed the locale but the error still appears in new SSH sessions. Why?

The locale settings need to be in both your local ~/.ssh/config (to not send locale) and your remote ~/.bashrc (to set a valid locale). Also, changes to locale settings require logging out and back in to take full effect. Some programs cache locale settings at startup.