GrepBoard/Manuals
605 manuals ·

Fix "setlocale: LC_ALL: cannot change locale" on Ubuntu 24.04

·Tested on Ubuntu 24.04 (Docker) · locales 2.39-0ubuntu8.9 · 2026-10·Test scope ↓·4 steps

Ubuntu "setlocale: LC_ALL: cannot change locale" means the locale you set was never generated. Check with locale -a, then run locale-gen or switch to C.UTF-8.

output
bash: warning: setlocale: LC_ALL: cannot change locale (ko_KR.UTF-8)

The locale that LC_ALL points to (ko_KR.UTF-8) has not been generated on this system. The command still runs, but character handling falls back to the default (C). Generate that locale with locale-gen, or point the variable at a locale that already exists (C.UTF-8), and the warning goes away. If it only appears when you SSH into a server, your client's locale was sent along; see step 4.

[1] List the locales on the system. The ubuntu:24.04 container image and minimal installs have almost none:

console
$ locale -aCC.utf8POSIX

If the locale in parentheses is not in the list, that is the cause. The list shows lowercase utf8 (ko_KR.utf8), which is the same as ko_KR.UTF-8.

Other programs report the same cause differently:

output
perl: warning: Setting locale failed.perl: warning: Please check that your locale settings:	LANGUAGE = (unset),	LC_ALL = "ko_KR.UTF-8",	LANG = (unset)    are supported and installed on your system.

The locale command prints Cannot set LC_CTYPE to default locale: No such file or directory.

[2] Find which variable set that value. The LC_ALL in the message is the name of the offending variable.

console
$ env | grep -E '^(LANG|LANGUAGE|LC_)'$ grep -sE 'LANG|LC_' /etc/default/locale ~/.bashrc ~/.profile /etc/environment

An export LC_ALL=… line in a shell startup file is the cause. If it is nowhere and only shows up over SSH, go to step 4.

[3] Generate the locale. On Ubuntu, locale-gen from the locales package takes the name directly:

console
$ sudo apt install locales$ sudo locale-gen ko_KR.UTF-8Generating locales (this might take a while)...  ko_KR.UTF-8... doneGeneration complete.$ locale -aCC.utf8POSIXko_KR.utf8

The same command no longer warns. To make it the system default, write it to /etc/default/locale with update-locale; it applies to new login sessions.

console
$ sudo update-locale LANG=ko_KR.UTF-8$ cat /etc/default/localeLANG=ko_KR.UTF-8

If you do not need that locale (English output on the server is fine), switching the variable to C.UTF-8 is enough. It is always present and handles UTF-8 text.

console
$ export LC_ALL=C.UTF-8

In container images, set ENV LANG=C.UTF-8 in the Dockerfile, or install locales and run locale-gen in a build step if you need a specific language.

[4] If it only happens over SSH, your client's locale variables were passed to the server. Ubuntu's default config has the client send LANG and LC_* and the server accept them:

console
$ grep -n 'SendEnv' /etc/ssh/ssh_config51:    SendEnv LANG LC_*$ grep -n 'AcceptEnv' /etc/ssh/sshd_config121:AcceptEnv LANG LC_*

man ssh_config notes the server must be configured to accept the variables for them to arrive. So if your machine uses ko_KR.UTF-8, a server without that locale prints this warning. Ways to fix it:

WhereHow
ServerGenerate the locale as in step 3. The cleanest fix
ClientUse a locale the server has, just for that connection: LC_ALL=C.UTF-8 ssh server1

Removing the server's AcceptEnv line also works, but it affects every user, so leave that to the admin.

On Rocky Linux 9, dnf prints Failed to set locale, defaulting to C.UTF-8 in a similar situation and the fix uses different packages — see Fix Rocky 9 dnf "Failed to set locale, defaulting to C.UTF-8".

Analyze your auth.log (SSH) log in the browser ↗ — nothing is uploaded.

Check it with the ssh_config generator tool ↗ — calculated in your browser.

#locale#locale-gen#ubuntu#ssh