Error Codes Wiki

Locale Errors — Cannot Set LC_ALL and Character Encoding Issues on Linux

Informationalsystem

Overview

Fix Linux locale errors including 'cannot set LC_ALL', missing locale, UTF-8 encoding failures, and locale generation issues on servers.

Key Details

  • Locales define language, character encoding, date/time format, and number formatting for the system
  • The 'cannot set LC_ALL' warning appears when the specified locale is not generated on the system
  • UTF-8 is the recommended encoding for modern Linux systems
  • SSH connections may forward the client's locale to the server, causing errors if that locale is not available
  • Minimal Docker containers and cloud server images often lack locale packages

Common Causes

  • Required locale not generated on the system (e.g., en_US.UTF-8 not in /etc/locale.gen)
  • SSH forwarding the client's locale (LC_ALL, LANG) to a server that does not have it installed
  • Docker container built from minimal base image without locale packages
  • locale-gen not run after adding a locale to /etc/locale.gen

Steps

  1. 1Check current locale: 'locale' shows all locale settings, 'locale -a' lists available locales
  2. 2Generate locale on Debian/Ubuntu: 'sudo locale-gen en_US.UTF-8 && sudo update-locale LANG=en_US.UTF-8'
  3. 3Generate locale on RHEL/CentOS: 'sudo localedef -i en_US -f UTF-8 en_US.UTF-8'
  4. 4Stop SSH locale forwarding: comment out 'SendEnv LANG LC_*' in /etc/ssh/ssh_config on the client
  5. 5For Docker: add 'RUN apt-get install -y locales && locale-gen en_US.UTF-8' and 'ENV LANG=en_US.UTF-8' to Dockerfile

Tags

localelc-allutf-8encodinginternationalization

Related Items

More in System

Frequently Asked Questions

Your SSH client forwards local locale settings (LANG, LC_ALL) to the server. If the server does not have those locales installed, you get warnings. Either install the locale on the server or disable SSH locale forwarding.