LANG
Sets the default locale for all locale categories that are not explicitly set by a more specific LC_* variable. Affects language, character encoding, date/time formatting, and number formatting. The value typically includes language, territory, and encoding.
Last updated:
LANG sets the default locale — language, region, and crucially the character encoding — for any locale category not overridden by a more specific LC_* variable. The encoding suffix (`.UTF-8`) is the part that breaks real programs: when LANG is unset or `C`/`POSIX`, the system assumes ASCII, and tools like Python (pre-3.7), Perl, Click, and psql throw UnicodeDecodeError or mangle non-ASCII output. This is the classic 'works on my laptop, fails over SSH/in Docker' bug, because minimal server and container images ship with no UTF-8 locale generated.
- Provider
- General / OS
- Category
- locale
- Set by
- Set in /etc/locale.conf, shell profile, or system settings
- Example
- en_US.UTF-8
How to set LANG
bash
export LANG=en_US.UTF-8
locale # verify what is actually activeDocker (portable UTF-8, no locale-gen)
ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8References
Frequently Asked Questions
How do I fix UnicodeDecodeError / mangled UTF-8 over SSH or in Docker?
The environment is missing a UTF-8 locale. Set LANG (and often LC_ALL) to a UTF-8 value. In containers prefer C.UTF-8, which is always available; on a full system use en_US.UTF-8 after generating it with locale-gen. Run `locale` to confirm the encoding actually took effect.
Stay up to date
Get notified about new guides, tools, and cheatsheets.