49

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=
62

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

  • 1
    It worked, but only after I logged out and then logged in again. – Forivin Aug 16 '17 at 8:10
  • Worked for me too! – Jamie Ivanov Apr 4 '18 at 19:57
  • editing /etc/locale.gen does't did the job for me (did logout/login), but locale-gen solved my tmux: need UTF-8 locale (LC_CTYPE) problem on Debian 4.9.82 – eapo May 30 '18 at 21:59
  • 2
    @eapo As I state in my answer, you need to edit /etc/locale.gen and then run locale-gen. – Gilles 'SO- stop being evil' May 30 '18 at 22:30
  • I missed the bit about enabling en_US.UTF-8 as well and your own locale. I found out the hard way then circled back here to make my own answer before realising it was here all along. – Alastair McCormack Feb 9 at 18:49
19

Top rated solution didn't helped 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.

  • 2
    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: wiki.debian.org/Locale – Pitone Maledetto Jan 26 '18 at 9:29
6

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
6

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_*
  • Both of these are uncommented for me but problem still arises. (RPi3, macOS10.14) – jorijnsmit Oct 9 '18 at 6:30
  • Commented out the line now. Don't really have the opportunity to test but sounds more logical this way... Thanks. – jorijnsmit Oct 9 '18 at 15:38
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.