18

I just installed CentOS 6 and whenever I login to the system via SSH remotely, I get the following error:

-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8)

When I type "locale" on the command line, I get the following output:

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

What can be the problem? How can I solve this issue?

user9517
  • 114,104
  • 20
  • 206
  • 289
Cem
  • 533
  • 3
  • 6
  • 14
  • your solution of commenting out the SendEnv LANG LC_* arg worked for me on Mac OS X 10.7.5 –  Dec 19 '12 at 07:49

11 Answers11

18

Solved this by disabling "Set locale environment variables on startup" in Terminal Settings > Advanced as per this screenshot.

enter image description here

NOTE: If you use iTerm2 you can disable the "Set locale variables automatically" option in Preferences > Profiles > Terminal

Camaleo
  • 103
  • 4
Nils
  • 181
  • 1
  • 2
  • 1
    This worked for me. Specifically, Terminal.app was setting "LC_CTYPE=UTF-8" which then caused the errors reported by the OP. Alternatively, `unset LC_CTYPE` or `export LC_CTYPE=en_US.UTF-8` fixup the problem after login. – tardate May 02 '13 at 09:53
  • This solved it for me, thx – pjvds Mar 06 '15 at 10:02
12

Simple way:

Add

 LC_CTYPE="en_US.UTF-8"

to /etc/sysconfig/i18n.

slm
  • 7,355
  • 16
  • 54
  • 72
gpupo
  • 1,114
  • 2
  • 10
  • 12
10

On the server you ssh from do you have a locale set via an environment variable? In looking at my CentOS 6 installation, the only locale that I can find supported is identified as en_US.utf8 (discovered using locale -a command). Could this be the problem?

In my testing, when I set the LC_ALL environment variable to en_US.UTF-8, ssh'd to the server, the output of my locale command was set to POSIX in my case. This the same as when I have NOT set (i.e. unset) the LC_ALL variable before ssh'ing.

When I set my LC_ALL variable to en_US.utf8 or en_US.utf-8, ssh'd to my CentOS 6 box, the output of the locale was the same as what was set on the source box.

Notice I used no caps for UTF also.

mdpc
  • 11,698
  • 28
  • 51
  • 65
  • 11
    By the way, I noticed that this was occurring from my Mac OS X Lion ssh settings. I edited /etc/ssh_config file and commented SendEnv LANG LC_*. It solved my problem. – Cem Oct 28 '11 at 12:30
  • @Cem Thanks for the tip, this indeed fixes it on Mac OS X Lion. – Zsolt Török Apr 15 '13 at 07:37
2

What worked for me was adding a symlink in the CentOS server like this:

ln -s /usr/lib/locale/en_US.utf8 /usr/lib/locale/UTF-8

Once you do that commands like this work:

export LC_CTYPE=UTF-8

If you don't, this last command fails with this error:

-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory

Now, an even simpler solution is just adding this line to /etc/bashrc in the server:

export LC_CTYPE="en_US.utf8"
gnrfan
  • 171
  • 5
2

I've got this specific message, when login from a Solaris X to a Centos host.

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

The problem is coming from 2 settings:

  1. In my default system ssh_config, I ask the system to pass those variable.

Send locale-related environment variables SendEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES

  1. On my source host, thoses settings was set this way:

    SOURCE# LANG= LC_CTYPE=fr_FR.UTF-8 LC_NUMERIC=fr_FR.UTF-8 LC_TIME=fr_FR.UTF-8 LC_COLLATE=fr_FR.UTF-8 LC_MONETARY=fr_FR.UTF-8 LC_MESSAGES=fr.UTF-8 LC_ALL=

But, as you can see, the LC_MESSAGES, is set to fr.UTF-8, which is not an option on my destination host.

 DEST#locale -a | grep fr_FR
 fr_FR
 fr_FR@euro
 fr_FR.iso88591
 fr_FR.iso885915@euro
 fr_FR.utf8

The problem was solved forcing on my source host, on .bash_profile: # export LC_ALL=fr_FR.UTF-8 export LANG=fr_FR.UTF-8

I could have solved it by asking my dest host not to take this variable from any ssh connection (generally, or by creating a locale ssh_config file for my user)

Kaalahaan
  • 21
  • 2
1

This was my fix in the past for locale errors.

Run the following: locale-gen

Then edit /etc/locale.gen. Make sure the following is uncommented:

en_US.UTF-8 UTF-8  
en_US ISO-8859-1  

generate locale

locale-gen
Thomas Vincent
  • 1,090
  • 6
  • 13
1

On a local Centos 6.2 system: This did not help:

localedef -i en_US -f UTF-8 en_US.UTF-8

This worked:

localedef --no-archive -i en_US -f UTF-8 en_US.UTF-8

I also deleted locale-archive in /usr/lib/locale. I do not know if this was necessary.

chutz
  • 7,569
  • 1
  • 28
  • 57
BobM
  • 11
  • 1
1

With Iterm2, is different.
Go to Iterm2 -> Preferences, Then Go to Profiles tab, and choose the Terminal tab from the bottom.
Go to Environment category, and unmark;

Set locale variables automatically

Finally, close and start a new session.

enter image description here

crsuarezf
  • 111
  • 3
0

On my CentOS 8 (minimal server installation) I successfully set my locale variables like this.

Either

echo 'LANG="en_US.UTF-8"' > /etc/locale.conf

OR

echo 'LC_ALL="en_US.utf8"' > /etc/locale.conf

Relogon and call locale to verify the result.

MrCalvin
  • 305
  • 1
  • 4
  • 17
0

and make sure LC_ALL="en_US.UTF-8" is in or added to the /etc/sysconifg/i18n

example content

LANG="en_GB.UTF-8"
SYSFONT="latarcyrheb-sun16"
LC_ALL="en_US.UTF-8" 
Pothi Kalimuthu
  • 5,734
  • 2
  • 24
  • 37
mayod
  • 1
-3

edit /etc/sysconfig/i18n

Change LANG="us" to LANG="en_US"

Save and exit, log out and back in.

Rex
  • 7,815
  • 3
  • 28
  • 44
NateDJ
  • 1