bash warns that it cannot change the locale after you log in to a server
bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)Short answer
The shell was told to use a locale that is not built on the server. Run locale -a to see what exists, generate the missing one with locale-gen, and set it with update-locale. If it only happens over SSH, your client is sending a locale the server does not have, so stop forwarding it.
Fix it fast
1Find out which cause you have
Print which locale variables are set and which locales the machine can actually use. The one named in the warning must appear in the second list.
locale locale -a2Match what you see, then jump to its fix
- 1
the name in the warning is missing from the output of locale -aThe locale was never generated on this serverFix - 2
the warning appears only after ssh login, and a local console login is cleanYour SSH client forwards a locale the server does not haveFix - 3
locale prints LC_ALL=something, and setting LANG does not change the resultLC_ALL is set by hand and overrides every other locale settingFix
- 1
What does the error look like?
bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
Cause 1 of 3
The locale was never generated on this server
1Check
Minimal server images ship only locale templates. A locale is compiled on the machine only after it is listed in /etc/locale.gen and locale-gen is run.
locale -a
grep -n "en_US.UTF-8" /etc/locale.gen2Fix
Build the locale, then make it the system default.
sudo locale-gen en_US.UTF-8
sudo update-locale LANG=en_US.UTF-83Verify
Open a new session. The warning is gone and locale shows the new value.
locale -a | grep -i en_US
localeConfirmed by manpages.ubuntu.com
Cause 2 of 3
Your SSH client forwards a locale the server does not have
1Check
Debian-based clients set SendEnv LANG LC_* in ssh_config and Debian-based servers set AcceptEnv LANG LC_* in sshd_config. The server copies the client's LANG, which names a locale it lacks.
echo "$LANG $LC_ALL"
grep -E "SendEnv|AcceptEnv" /etc/ssh/ssh_config /etc/ssh/sshd_config2Fix
Either generate that locale on the server as in the first cause, or stop the client sending it for this host. A pattern with a leading minus clears variables an earlier SendEnv line set, so the Debian default does not apply to this host.
# ~/.ssh/config on your machine
Host my-server
SendEnv -LANG -LC_*3Verify
Log in again and the warning no longer prints.
ssh my-server localeConfirmed by manpages.ubuntu.com
Cause 3 of 3
LC_ALL is set by hand and overrides every other locale setting
1Check
When LC_ALL is non-empty its value is used for every category, before any LC_* or LANG variable. A stale export in .bashrc or .profile keeps asking for a missing locale.
grep -n "LC_ALL" ~/.bashrc ~/.profile ~/.bash_profile /etc/environment /etc/default/locale 2>/dev/null2Fix
Delete the line, or point it at a locale that exists, then start a new shell.
unset LC_ALL
# and remove the export LC_ALL=... line from the file grep found3Verify
locale shows an empty LC_ALL and no warning is printed.
localeConfirmed by manpages.ubuntu.com
How do I stop it coming back?
- Generate the locales you use in your server provisioning script instead of fixing each machine by hand.
- Use one explicit LANG, such as en_US.UTF-8 or C.UTF-8, across all servers.
- Avoid exporting LC_ALL in shell startup files; set LANG instead.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Servers
apt-get does not exist on this EC2 instance
sudo: apt-get: command not found
apt-get belongs to Debian and Ubuntu.
2 causes, each with a fixServers
Syntax error: redirection unexpected when a Bash script runs under sh
script.sh: 12: Syntax error: redirection unexpected
The operators <<< (here-string) and &> are Bash features.
3 causes, each with a fixServers
ping is missing inside a Docker container
sh: 1: ping: not found
Base images such as ubuntu are minimal, so ping is simply not installed.
2 causes, each with a fixServers
Running ps inside a container says command not found
bash: ps: command not found
Slim Debian and Ubuntu images do not ship the procps package, and ps comes from procps.
2 causes, each with a fixServers
GitHub Actions step fails writing to GITHUB_OUTPUT
Error: Invalid format '...'
The runner reads GITHUB_OUTPUT line by line, and every entry must be name=value or a name<<DELIMITER block.
3 causes, each with a fixServers
pip install worked but the jupyter command is not found
bash: jupyter: command not found
The shell can only run programs that sit in a folder on PATH.
2 causes, each with a fix