24

I occasionally get locale errors and I've tried to run dpkg-reconfigure locales to fix the problem. Here's the output:

:~$ sudo dpkg-reconfigure locales
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_CTYPE = "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_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
/usr/bin/locale: Cannot set LC_CTYPE to default locale: No such file or directory
/usr/bin/locale: Cannot set LC_ALL to default locale: No such file or directory
Generating locales (this might take a while)...
  en_US.UTF-8... done
Generation complete.
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_CTYPE = "UTF-8",
    LANG = "C"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_CTYPE = "UTF-8",
    LANG = "C"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

I looked for /usr/bin/locale but it doesn't exist on my system. Do I need to create it? What do I put in there?

Also I found a related question that says the cause of his problem was in the sshd_config file. The file had the following entry:

AcceptEnv LANG LC_*

I'm mainly concerned that it may cause problems for my VPS, otherwise if it's nothing major I'll be happy to ignore the problem. What should I do? thanks!

blogjunkie
  • 411
  • 1
  • 3
  • 6
  • There seem to be a bug with some debian based distribution (including ubuntu). Using fr_FR.UTF-8 was giving problems (and the locale existed). Doing a `locale-gen fr` would build all fr locales (fr_BE, fr_CH etc...) solves the issue. Perhaps try `locale-gen en` – Antony Gibbs May 28 '16 at 13:00
  • This same problem (LC_CTYPE=UTF-8, which is wrong) can happen when you login over ssh from a Mac to a linux box, and your terminal automatically sets environment variables. There's a checkbox for that. Uncheck it, and you're good to go. In iTerm it's in the profile->Terminal Tab. – raarts May 28 '16 at 12:47

13 Answers13

16

first:

sudo apt-get purge locales

then:

sudo aptitude install locales

and the famous:

sudo dpkg-reconfigure locales

This rids the system of locales, then re-installs locales and downgrades libc6 from 2.19 to 2.13 which is the issue. Then configures locales again.

tkjef
  • 369
  • 3
  • 6
15

If this happens when SSHing to your box, but not on console, try reconfiguring your ssh client (on your local machine). On Mac OS X for example edit /private/etc/ssh_config and comment out

# SendEnv LANG LC_*

Thanks to the post of bredman on the Rasberry Pi Bulletin Board.

Falcon Momot
  • 24,975
  • 13
  • 61
  • 92
Adrian Zaugg
  • 366
  • 2
  • 11
8

I had this problem for a long time and all the usual advice about dpkg-reconfigure locales, locale-gen, etc didn't help. So I played around a little bit with the environment variables, and what I found was that the system was borking on the LC_CTYPE environment variable! UTF-8 is not a valid value for it. Setting it to en_US.UTF-8 fixed it.

To make the change permanent, I ran

update-locale LC_CTYPE=en_US.UTF-8

which writes to /etc/default/locale. And then reboot the system for it to take effect completely.

chicks
  • 3,639
  • 10
  • 26
  • 36
Hongli Lai
  • 2,112
  • 4
  • 22
  • 27
  • Unfortunately, this yields `perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = (unset), LC_ALL = (unset), LC_CTYPE = "UTF-8", LANG = "en_US.UTF-8" are supported and installed on your system. perl: warning: Falling back to the standard locale ("C"). *** update-locale: Error: invalid locale settings: LC_CTYPE=en_US.UTF-8` – mehov Dec 04 '19 at 13:32
3

If you disabled PAM authentication for ssh in /etc/ssh/sshd_config (UsePAM no) the responsible configuration in /etc/pam.d/login isn't effective:

session required pam_env.so readenv=1 envfile=/etc/default/locale

The result: /etc/default/locale seems to have no effect.

So you have to configure your client to send the LANG vars or export the env vars in the profile scripts like ~/.profile, ~/bashrc etc.

More: http://wiki.debian.org/Locale#Standard

2

I've seen this before on older Debian installs, and while annoying, I've never seen it cause a problem.

If

  /usr/bin/locale 

is missing, try (as root):

  apt-get install libc-bin

that should install libc-bin, providing /usr/bin/locale.

That AcceptEnv line in your sshd_config is pretty standard, and shouldn't be the the cause of your problem here.

Chad Feller
  • 776
  • 5
  • 6
  • libc-bin was already installed, so I updated it and tried running `dpkg-reconfigure locales` again. No joy :( – blogjunkie Aug 17 '11 at 11:24
  • Does /usr/bin/locale exist now? If so, what is the output of: `locale -a` and what is in `/etc/default/locale` ? – Chad Feller Aug 17 '11 at 13:23
  • The contents of `/etc/default/locale' : # File generated by update-locale LANG=en_US.UTF-8 – blogjunkie Aug 17 '11 at 16:53
  • `locale -a` gives me: locale: Cannot set LC_CTYPE to default locale: No such file or directory C en_US.utf8 POSIX – blogjunkie Aug 17 '11 at 16:54
  • apt was claiming that libc-bin was installed, but at least one file was missing (/usr/bin/locale), and reinstalling libc-bin seems to have fixed that. Can you try `apt-get install --reinstall locales`? Then, for good measure, try `locale-gen`, which will regenerate any locales that are uncommented in `/etc/locale.gen` (you should have a line like `en_US.UTF-8 UTF-8`). After this, see if `locale -a` works. – Chad Feller Aug 17 '11 at 20:23
  • still didn't work :( `locale -a` returns the same output as above. Appreciate your time Chad, I might contact my host's support team for this. – blogjunkie Aug 18 '11 at 00:01
2

Did the following, as Manoj, but added it to #~/.bashrc:

export LC_ALL=en_US.utf8
export LANGUAGE=en_US.utf8
Hauge
  • 21
  • 1
2

Mac connecting to a fresh Debian 10 install. None of the answers googled all over Stack Exchange helped. Here's what did (and was straightforward and reliable too):

sed -i "s/^AcceptEnv/#AcceptEnv/g" /etc/ssh/sshd_config

Run this on your Debian box and it will stop the connecting mac terminal from messing up the server locales (more info).

As a bonus, that may even improve security of the server.

mehov
  • 568
  • 1
  • 5
  • 14
1

I had this problem which was very bothering and spamming the terminal window. Main issue, that my client is MacOS box. See below.

As I have seen, all the solutions are locales package and settings related, but the root cause is SSH!

Remote Linux server, fresh installed Debian Buster complains:

locale
locale: Cannot set LC_CTYPE 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_US:en
LC_CTYPE=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=

I connect to remote systems from MacOS Terminal, which has setting:

uname -a
Darwin mac-pro.lan 19.6.0 Darwin Kernel Version 19.6.0: Tue Nov 10 00:10:30 PST 2020; root:xnu-6153.141.10~1/RELEASE_X86_64 x86_64

set | grep LC_
LC_CTYPE=UTF-8

Here it is! Local, non Linux standard language setting is passed to remote Linux server.

On remote Linux server edit the /etc/ssh/sshd_config and comment out the LC_ variable passthrough:

# Allow client to pass locale environment variables
#AcceptEnv LANG LC_*

Restart the ssh daemon:

systemctl restart sshd 

logout from remote ssh, login again, and vualia:

locale
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.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=

Not to bother with every single server, just fix your (MacOS client) side:

echo "export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8">>~/.bash_profile

if you use zsh use ~/.zprofile instead.

This way, you setup more Linux compatible language setting, and no more remote Linux server complains!

Arunas Bartisius
  • 669
  • 1
  • 6
  • 13
1

If you are getting the errors while ssh'ing to a remote system, and don't want to modify the remote system (by changing the sshd_config, for instance), you can do the following on your local system (assuming bash)

export LC_ALL=en_US
export LANGUAGE=en_US

and then ssh user@remote

1

On my fresh Debian installation (minimal) locales was completely missing. Installing it (aptitude install locales) and running locale-gen did the trick though. So guys, do as Chad Feller mentioned but check for having the package locales installed first.

1

I was using German VPS and couldn't change locale because there was no English language pack installed.

After installing I could finally change locale

aptitude install language-pack-en
valentt
  • 295
  • 3
  • 10
1

on Debian systems this will resolve your problem:

apt-get install locales-all

on Ubuntu systems install specific language pack, for example:

apt-get install language-pack-en

locale-gen en_US.UTF-8

Geza
  • 11
  • 3
0

Another option is to use grep command to search for specific locales.

## For example, search for English India ##
grep en_IN /etc/locale.gen
 
## Search for English US ##
grep en_US /etc/locale.gen
 
## Search for Japanese ##
grep ja_JP /etc/locale.gen

then,

felipe@SDF-1:~$ tail -f /etc/locale.gen
# zh_HK BIG5-HKSCS
# zh_HK.UTF-8 UTF-8
# zh_SG GB2312
# zh_SG.GBK GBK
# zh_SG.UTF-8 UTF-8
# zh_TW BIG5
# zh_TW.EUC-TW EUC-TW
# zh_TW.UTF-8 UTF-8
# zu_ZA ISO-8859-1
# zu_ZA.UTF-8 UTF-8

^C
felipe@SDF-1:~$ locale

LANG=en_US.UTF-8

LANGUAGE=en_US.utf8
LC_CTYPE="en_US.utf8"
LC_NUMERIC="en_US.utf8"
LC_TIME="en_US.utf8"
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=en_US.utf8

felipe@SDF-1:~$

also, helped me this:

felipe@SDF-1:~$ sudo locale-gen en_US.UTF-8
Generating locales (this might take a while)...
Generation complete.
felipe@SDF-1:~$ sudo localedef -i en_US -f UTF-8 en_US.UTF-8
felipe@SDF-1:~$ sudo export LANGUAGE=en_US.UTF-8
sudo: export: command not found
felipe@SDF-1:~$  sudo export LANG=en_US.UTF-8
sudo: export: command not found
felipe@SDF-1:~$ export LANGUAGE=en_US.UTF-8
felipe@SDF-1:~$ export LANG=en_US.UTF-8
felipe@SDF-1:~$ export LC_ALL=en_US.UTF-8
-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8): No such file or directory
felipe@SDF-1:~$ sudo locale-gen en_US.UTF-8
Generating locales (this might take a while)...
Generation complete.
felipe@SDF-1:~$ export LC_CTYPE=en_US.UTF-8
felipe@SDF-1:~$ export LC_ALL=en_US.UTF-8
-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
felipe@SDF-1:~$ 
felipe@SDF-1:~$ 
felipe@SDF-1:~$ locale
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
LC_CTYPE="en_US.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=en_US.UTF-8
felipe@SDF-1:~$ 

I just got to something else:

I have to add the fact that I had the same problems, still. But then I tried this, and it got fixed:

Added it to

#~/.bashrc:

export LC_ALL=en_US.utf8
export LANGUAGE=en_US.utf8

and then, restarted SSH demon:

systemctl restart sshd
Felipe
  • 1
  • 2