BadValue Invalid or no user locale set. Please ensure LANG and/or LC_* environment variables are set correctly

115,058

Solution 1

Generating locales

Missing locales are generated with locale-gen:

locale-gen en_US.UTF-8

Alternatively a locale file can be created manually with localedef:[1]

localedef -i en_US -f UTF-8 en_US.UTF-8

Setting Locale Settings

The locale settings can be set (to en_US.UTF-8 in the example) as follows:

export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
dpkg-reconfigure locales

The dpkg-reconfigure locales command will open a dialog under Debian for selecting the desired locale. This dialog will not appear under Ubuntu. The Configure Locales in Ubuntu article shows how to find the information regarding Ubuntu.

Solution 2

you can use the below command on terminal

export LC_ALL=C

Solution 3

vim /etc/default/locale

add to it:

LC_ALL="en_US.UTF-8"

Solution 4

Amazon Linux AMI

Permanent solution for ohmyzsh:

$ vim ~/.zshrc

Write there below:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8

Update changes in current shell by: $ source ~/.zshrc

Solution 5

adding the following lines to my /etc/environment file worked

LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
Share:
115,058
Majid Zandi
Author by

Majid Zandi

python developer. (Don’t worry about your choices: just build something.)

Updated on November 18, 2020

Comments

  • Majid Zandi
    Majid Zandi over 3 years

    When I run mongo, I get the warning:

    Failed global initialization: BadValue Invalid or no user locale set. Please ensure LANG and/or LC_* environment variables are set correctly.

  • Majid Zandi
    Majid Zandi over 9 years
  • benek
    benek almost 8 years
    To have it in all seasons : echo "export LC_ALL=C" >> ~/.bashrc
  • Damien Romito
    Damien Romito almost 8 years
    The other answers are not permanent solutions. We have to enter those commands each time we connect. Edit that file only once is the perfect solution! Thank you
  • lingyfh
    lingyfh almost 8 years
    Only execute on your terminal. not server
  • Philipp Jahoda
    Philipp Jahoda over 7 years
    This is the only permanent solution that worked for me. Definitely deserves more upvotes!
  • GeekHades
    GeekHades over 7 years
    This way just for current seesion, Just for one time, Not for forever!
  • BorisS
    BorisS about 7 years
    Worked. Importing thing to note is that you need to logout and login again in order for this to work.
  • Nidhin David
    Nidhin David over 6 years
    hi, I have accidently downvoted this question and missed it. Now I cannot remove it. It says my vote is locked. I 'am really sorry. If there is any other way, let me know.
  • DLight
    DLight over 6 years
    For those wondering: What does “LC_ALL=C” do? unix.stackexchange.com/questions/87745/what-does-lc-all-c-do
  • Habib
    Habib over 5 years
    How to save this file?
  • Mirko
    Mirko almost 5 years
    This did it for me on a raspberry: sudo localedef -i en_US -f UTF-8 en_US.UTF-8 Thank you!!