Fix the “Failed to set locale, defaulting to C.UTF-8” Error in CentOS 8 / RHEL 8
If you’re seeing that annoying message at login or when running a script, it means your system can’t load the language settings you expect. The result is a fallback to the neutral C.UTF‑8 locale, which can break software that relies on proper encoding or regional data. This article walks through why it happens and shows you a quick fix.
Why the “Failed to set locale” Error Happens
The error appears when the system’s locale files are missing, corrupted, or mis‑referenced in /etc/locale.conf. In a recent upgrade I saw this pop up right after installing glibc-langpack-en but forgetting to reboot. The OS can’t find the requested language data and silently switches to C.UTF‑8.
Quick Fix with localectl
1. Check current locale settings
localectl status
It shows you what the system believes it’s using now, so you know what needs changing.
2. Set a valid locale – for example, U.S. English:
sudo localectl set-locale LANG=en_US.UTF-8
localectl updates /etc/locale.conf atomically and tells the system to reload its settings.
3. Verify the change
echo $LANG
You should now see en_US.UTF-8. If it still shows C.UTF‑8, skip to the next step.
Checking Installed Language Packs
Sometimes the locale files simply aren’t installed:
sudo dnf list installed | grep langpack
If you don’t see a package ending in .langpack, install one that matches your target language, e.g.:
sudo dnf install glibc-langpack-en
The locale data lives inside these packages. Without them, any request to use en_US.UTF-8 will fail.
Removing Old or Conflicting Configs
A stray line in /etc/locale.conf can trip you up:
sudo nano /etc/locale.conf
Make sure it contains only the line LANG=en_US.UTF-8. Delete any duplicated or contradictory entries. Also check /usr/lib/locale/locale.alias for missing aliases.
Duplicate entries confuse the locale loader, and missing aliases can cause the fallback to trigger.
Rebooting and Verifying
After making changes, reboot:
sudo reboot
Upon return, run localectl status again. The output should now list your chosen locale as both “System Locale” and “Current Locale.”
If you’re still stuck after a reboot, it’s probably because the language pack didn’t install properly. Double‑check the package list or try reinstalling:
sudo dnf reinstall glibc-langpack-en
What If It Still Persists
- Check SELinux contexts – sometimes mislabeling can block access to locale files:
sudo restorecon -v /usr/lib/locale
- Look at logs – journalctl -xe | grep locale may reveal deeper issues.
If all else fails, consider adding a fallback in /etc/environment:
LANG=en_US.UTF-8
This is a blunt instrument but can force the shell to use the correct encoding until you fix the root cause.