CentOS 6 and locale error

Solution 1:

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

Solution 2:

Simple way:

Add

 LC_CTYPE="en_US.UTF-8"

to /etc/sysconfig/i18n.


Solution 3:

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.


Solution 4:

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"

Solution 5:

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)