93

When I always try to install new package I get this message:

Can't set locale; make sure $LC_* and $LANG are correct!
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = "en_GB:en",
    LC_ALL = (unset),
    LC_CTYPE = "en_GB.UTF-8",
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory

My OS is Debian Jessie 8.3 (Mate) using English with French keyboard. When I type locale, I get this:

locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LANGUAGE=en_GB:en
LC_CTYPE=en_GB.UTF-8
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Ismail Sensei
  • 1,179
  • 1
  • 10
  • 13

5 Answers5

122

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).

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
37

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.

Andhi Irawan
  • 107
  • 4
ssasa
  • 571
  • 5
  • 7
  • 3
    Using LC_ALL is strongly discouraged as it overrides everything. Please use it only when testing and never set it in a startup file. as per: https://wiki.debian.org/Locale – Pitone Maledetto Jan 26 '18 at 09:29
15

These commands saved my life

# echo "LC_ALL=en_US.UTF-8" >> /etc/environment
# echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
# echo "LANG=en_US.UTF-8" > /etc/locale.conf
# locale-gen en_US.UTF-8
multithr3at3d
  • 522
  • 2
  • 13
Taras Vaskiv
  • 251
  • 2
  • 5
14

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_*
gman
  • 240
  • 2
  • 8
  • Both of these are uncommented for me but problem still arises. (RPi3, macOS10.14) – gosuto Oct 09 '18 at 06:30
  • Commented *out* the line now. Don't really have the opportunity to test but sounds more logical this way... Thanks. – gosuto Oct 09 '18 at 15:38
  • Works on `raspberry pi` with `Debian 10`. What is the idea? Throwing away `locale settings` in a ssh session that is sent from the client host. – Timo May 15 '21 at 15:09
2

You need to install the package locales (or locales-all or the en_GB locale, depending on the Debian version you have).

A workaround not to have such errors: set LANG=C to root, so that it will use no locales.

Giacomo Catenazzi
  • 2,630
  • 9
  • 15