Problem of Can't set locale; make sure $LC_* and $LANG are correct!

Debian ships locales in source form. They need to be compiled explicitly. The reason for this is that compiled locales use a lot more disk space, but most people only use a few of them.

Run dpkg-reconfigure locales as root, select the locales you want in the list (with your settings, you need en_GB and en_US.UTF-8 — I recommend selecting en_US and en_GB.UTF-8 as well) then press <OK>.

Alternatively, edit /etc/locale.gen, uncomment the lines for the locales you want, and run locale-gen as root.

(Note: on Ubuntu, this works differently: run locale-gen with the locales you want to generate as arguments, e.g. sudo locale-gen en_GB en_US en_GB.UTF-8 en_US.UTF-8.)

Alternatively, Debian now has a package locales-all which you can install instead of locales. It has all the locales pre-generated. The downside is that they use up more disk space (112MB vs 16MB).


The top-rated solution didn't help in my case, so I used this one:

export LC_ALL="en_US.UTF-8"
sudo dpkg-reconfigure locales

After that, I logged out and logged in and error was missing.


If you're having this issue on a raspberry pi (or other?) and you're getting the error when you ssh to the pi there are 2 other solutions

One is edit /etc/ssh/sshd_config on the pi and comment out the line

AcceptEnv LANG LC_*

for example sudo nano /etc/ssh/sshd_config

After which you should restart the ssh server

sudo systemctl restart ssh

The other is on your client machine (not the pi) edit /etc/ssh/ssh_config (different path from above) and comment out the line

SendEnv LANG LC_*

Tags:

Locale

Debian