Whenever I run yum command, I get an error or warning that read as Failed to set locale, defaulting to C. How do I fix this issue on CentOS 7 Linux server? Why do I get “Failed to set locale, defaulting to C” when using yum on CentOS 6 or Fedora Linux system? How do I fix it?

Locales define language and country-specific setting for your programs and shell session. You can use locales to see the date, time, number, currency and other values formatted as per your country or language on a Linux or Unix-like system. To set system’s locale, you need use shell variable. For example, LANG variable can be used to set en_US (English US) language. Let us see how to fix “Failed to set locale, defaulting to C.UTF-8” on latest version of RHEL or CentOS too.

Understanding “Failed to set locale, defaulting to C” when using yum

It means local values did not correctly setup on your CentOS Linux server or desktop system. The following instructions should help you to fix this problem.

How do I find out current values for my language?

Just type the following command:
$ locale
# locale
Sample outputs:

Fig.01: How do I show current locale settings on a Linux or Unix?

How do I solve this problem?

To set i18n stuff CentOS/Fedora and RedHat Enterprise Linux call a special script called /etc/profile.d/lang.sh. Make sure this file exist in your system:
$ ls -l /etc/profile.d/lang.sh
If file exist just call it:
$ source /etc/profile.d/lang.sh
Verify that LANG and LC_* shell variable are set:
$ echo "$LANG"
$ echo "$LC_CTYPE"

How to set my own LANG and LC_ALL/LC_CTYPE variables

You can set it manually in your own directory as follows:
$ vi ~/.bashrc
OR globally in /etc/profile.d/ for bash/sh/ksh shell:
$ sudo vi /etc/profile.d/my-custom.lang.sh
Append the following
## Indian English ##
export LANG=en_IN
export LANGUAGE=en_IN:en
export LC_CTYPE=en_IN.UTF-8

For US English:
## US English ##
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8

Save and close the file. Log out and log in again. Or just call this file:
$ source /etc/profile.d/my-custom.lang.sh

How do I test it?

Now you can use yum command without any issues:
$ sudo yum update
$ sudo yum search nload
$ sudo install nload

Fig.02: Look Maa, no warning message with yum command

A note about CentOS / RHEL 8

Use the localectl command to fix Failed to set locale defaulting to C warning as follows instead of editing files:
sudo localectl set-locale LANG=en_IN.UTF-8

Summing up

You learned how to Fix “Failed to set locale, defaulting to C.UTF-8” in CentOS 7 or 8 including RHEL based distros. The workaround also works on Fedora Linux. We can also use the localectl command to set locales as follows:
sudo localectl set-locale LANG=en_US.UTF-8
sudo localectl set-locale LANG=en_IN.UTF-8
sudo yum install foo
sudo dnf install foo

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
1 comment… add one
  • Skunk Jul 20, 2017 @ 22:05

    Hola. Como seria para ponerlo en espaol?

    Intente con estos paso pero igual me sigue mostrando el error, supongo que hay que ponerlo con mi idioma y mi hora local. No se como se escribe el código.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum