Why do I get "Failed to set locale, defaulting to C" when using yum?
Every time I run yum install
or yum update
, I get
Failed to set locale, defaulting to C
and then other information.
How can I avoid getting this warning?
I put the following locale relating setting in /etc/bashrc
(for all users, bash
):
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_COLLATE=C
export LC_CTYPE=en_US.UTF-8
then run:
source /etc/bashrc
or log off and log on.
Run
yum reinstall glibc-common
and then make sure that no process is deleting the /usr/lib/locale/locale-archive.* files.
I was getting same error on MacOS. When you ssh to a linux box, they refuse to setup an UTF-8
locale. You can see the differences in locale setting by running locale
command on your MacOS terminal and Linux box.
To fix this error open terminal -> preferences -> profiles -> Advanced and unset Set locale environment variables on startup
on your mac.
Now when you run locale
on mac. you can see that this change has set LC_CTYPE="C"
which was LC_CTYPE="UTF-8"
with previous setting.
you will have to close your terminal to take this effect and now login to your linux box and run yum update
.
Hope it helps :)
If you used SSH to connect to this host from a desktop machine, it's common for /etc/ssh/sshd_config
to contain
AcceptEnv LANG LC_*
which allows clients to propagate the values of those environment variables into new sessions. However, this will cause the locale variables to be set back to empty within your SSH session on the server you are configuring, if the locale isn't first correctly set ON YOUR DESKTOP MACHINE.
To Fix:
For example, in the Windows 10 Ubuntu Shell window, first do (NOTE: change all entries below to match your locale if it's not "en_US.UTF-8"):
sudo locale-gen en_US.UTF-8
sudo dpkg-reconfigure locales
Then close Ubuntu shell window and re-open, and then SSH into the server you are trying to configure and see if everything is now fine...
If not, then SSH into your server and do:
vi /etc/profile.d/custom.lang.sh
Then hit I
to enter "insert" mode. Then paste the below entries. Then ZZ
to save and exit:
## US English ##
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8
Then execute the following:
source /etc/profile.d/lang.sh
source /etc/profile.d/custom.lang.sh
Then:
reboot
See if that makes everything stop complaining about locale vars!