How to Fix “Failed to set locale, defaulting to C.UTF-8” in CentOS 8

Have you ever encountered the warning/error “Failed to set locale, defaulting to C.UTF-8” in CentOS 8 or RHEL 8? If yes, then this article describes how to fix this error. Note that this article should also work on any operating systems based on RHEL 8.

A locale is a set of basic system parameters that define things such as a user’s language, region and any special variant preferences that the user wants to see in their user interface.

Recommended Read: How to Change or Set System Locales in Linux

On POSIX platforms such as Linux and other Unix-like operating systems, locale identifiers are defined by ISO/IEC 15897. For example, UNITED STATES OF AMERICA (US) English using the UTF-8 encoding is en_US.UTF-8).

The following is a screenshot showing the warning/error when you run the dnf or yum command as shown.

Failed to set locale, defaulting to C.UTF-8
Failed to set locale, defaulting to C.UTF-8

To set system locale, use the localectl command. For example, if you want English – UNITED STATES OF AMERICA (US) using the UTF-8 encoding, run the following command.

# localectl set-locale LANG=en_US.UTF-8

Next, check if the system locale has been set by running the following command.

# localectl
# dnf install @postgresql
Failed to set locale, defaulting to C.UTF-8
Failed to set locale, defaulting to C.UTF-8

Note that even after setting the system locale, the warning persists. This implies that the language packs are missing. To install them, go to the next section.

If a particular language pack is missing on your system, you need to install it to fix the above error. However, you can install all language packs provided by the glibc-all-langpacks package which contains all locales.

# dnf install langpacks-en glibc-all-langpacks -y
Install Language Packs in CentOS 8
Install Language Packs in CentOS 8

Alternatively, if you want to install locales individually, and thus have a smaller package installation footprint on your system, run the following command (replace en with the locale-code you want).

# dnf install glibc-langpack-en

Using the above procedure, we managed to fix the “Failed to set locale, defaulting to C.UTF-8” in CentOS 8 or RHEL 8. Hoping that this worked for you as well, otherwise. give us feedback via the comment form below.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

13 Comments

Leave a Reply
  1. After trying the above solution, i.e installing langpacks, I locate gnome-control-center where I was able to change language from ANSI to English, in the Region & Language section. Set Language to English (United States) and Formats to United States (English).

    Locale now displays:
    LANG=en_US.UTF-8
    LC_CTYPE=”en_US.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=

    Reply
  2. RHEL 8.3 install script failed during install localectl status showed empty, but I have updated it however locale still shows “C” and gnome-terminal fails to open.

    $ locale
    
    LANG=C
    LC_CTYPE="C"
    LC_NUMERIC="C"
    LC_TIME="C"
    LC_COLLATE="C"
    LC_MONETARY="C"
    LC_MESSAGES="C"
    LC_PAPER="C"
    LC_NAME="C"
    LC_ADDRESS="C"
    LC_TELEPHONE="C"
    LC_MEASUREMENT="C"
    LC_IDENTIFICATION="C"
    LC_ALL=
    
    $ localectl status
    
       System Locale: LANG=en_US.UTF-8
           VC Keymap: us
          X11 Layout: us
           X11 Model: pc105+inet
         X11 Options: terminate:ctrl_alt_bksp
    

    Marv

    Reply
  3. Hi, it worked after installing this “dnf install glibc-langpack-en” in Centos 8 Docker container.

    Thanks a mission.

    Reply
  4. @Aaron,

    I’m using Ubi minimal image and DNF/yum not installed on it. It comes with microdnf.

    When I’m trying to install langpack-es, it fails saying the package not available in the base-os-8 repo. Any suggestions?

    I don’t want to install an all-langpack to keep the image size small.

    Reply
  5. Hi, I can’t find DNF. Any solution?

    No command ‘dnf’ found, did you mean:
    Command ‘df’ from package ‘coreutils’ (main)
    Command ‘fnf’ from package ‘confluence’ (universe)
    dnf: command not found

    Reply
    • @Chamara

      Are you using CentOS 8? It comes with DNF installed, alternatively, you can use the YUM package manager to install the packages.

      Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.