Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix locale issue in Red Hat distro?

I'm having a strange problem today in my RHEL system. My python script is returning:

>>> locale.setlocale(locale.LC_ALL, '')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.6/locale.py", line 513, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

WHen I run...

$ locale

The ouput is...

locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
...

I have been trying many suggestions but none of them solved my issue yet.

For example:

  • Reinstall glibc-common.
  • Export LC_ALL as environment variable into ~/.bashrc.
  • Change the file /etc/sysconfig/i18n'.
  • locale-gen does not exists in RHEL.

Does anyone has a good suggestion to solve my issue. Remembering that I'm using RHEL and not Ubuntu (there are many tutorials about locale issues and Ubuntu).

like image 675
jcfaracco Avatar asked Sep 12 '14 13:09

jcfaracco


People also ask

How do I fix locale in Linux?

One solution to fix this issue, first run the locale command to list the locales currently defined for your user account. To generate the missing locale and reconfigure locales, identify the name of your locale ( in my case de_DE. UTF-8 ), or use one another one that you prefer, such as en_US. UTF-8 .

How do I change the locale in redhat?

To change the default language you do not need to restart or reinstall Red Hat Enterprise Linux 5. You can do this as root by running the language selection application. This can be accessed from the system menu by clicking System => Administration => Language or typing system-config-language from a terminal.

How do I change the locale in Redhat 8?

Open the settings by clicking the drop down on the top right of the window and selecting the settings icon. Once the settings are open, click Region & Language and select your desired options.

How do I change the default locale in Linux?

How to Set System Locale in Linux. If you want to change or set system local, use the update-locale program. The LANG variable allows you to set the locale for the entire system. The following command sets LANG to en_IN.UTF-8 and removes definitions for LANGUAGE. To configure a specific locale parameter, edit the appropriate variable.

What is a locale in RHEL 8?

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.

What are the default locale environment variables in RHEL 7?

By default, RHEL 7 systems accept locale environment variables from ssh clients. The following locale environment variables will (if passed by the ssh client) be set in the environment before any login scripts are ran: The above output is from sshd_config.

How do I check if the locale has changed?

How to check locale changes. Log out of the current session - the locale is set when you login so any change happens at the next login. Verify any changes made using the locale command: If the locale isn't what you now expect it to be, you should verify that the steps above have been followed.


2 Answers

Add this to your /etc/environment:

LC_ALL=en_US.UTF-8
LC_CTYPE=en_US.UTF-8

Then logout and login to shell again and try executing your commands.

like image 177
Anderson So Avatar answered Oct 05 '22 08:10

Anderson So


In my case it was iTerm setting the locale variables automatically. I fixed it by going to the iTerm menu and then

Preferences ... > Profiles > "select your profile" > Terminal > uncheck "Set locale variables automatically" 
like image 30
Ivan Hristov Avatar answered Oct 05 '22 06:10

Ivan Hristov