env.dev

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
Gotcha: A bare Debian/Ubuntu container often has LANG unset and only the C locale available, so setting LANG=en_US.UTF-8 fails silently unless that locale was generated. Use LANG=C.UTF-8 (always present, locale-neutral but UTF-8 aware) in containers, or install/generate locales explicitly. Note LC_ALL overrides LANG entirely — if LC_ALL is set, changing LANG does nothing.

How to set LANG

bash

export LANG=en_US.UTF-8
locale   # verify what is actually active

Docker (portable UTF-8, no locale-gen)

ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8

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.

Was this helpful?

Stay up to date

Get notified about new guides, tools, and cheatsheets.

Browse all 242 environment variables →