145

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
  • 4,371
  • 5
  • 21
  • 29

6 Answers6

357

you can use the below command on terminal

export LC_ALL=C
Edson
  • 3,589
  • 2
  • 11
  • 4
85

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.

warvariuc
  • 57,116
  • 41
  • 173
  • 227
Majid Zandi
  • 4,371
  • 5
  • 21
  • 29
  • This did it for me on a raspberry: sudo localedef -i en_US -f UTF-8 en_US.UTF-8 Thank you!! – Mirko May 26 '19 at 18:15
33
vim /etc/default/locale

add to it:

LC_ALL="en_US.UTF-8"
liyuan_t
  • 331
  • 3
  • 3
  • 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 – Damien Romito Jun 29 '16 at 00:47
  • This is the only permanent solution that worked for me. Definitely deserves more upvotes! – Philipp Jahoda Sep 13 '16 at 10:13
  • 1
    Worked. Importing thing to note is that you need to logout and login again in order for this to work. – BorisS Mar 08 '17 at 14:43
25

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

dimpiax
  • 12,093
  • 5
  • 62
  • 45
24

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

LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
Fırat Küçük
  • 5,613
  • 2
  • 50
  • 53
Tim
  • 1,238
  • 1
  • 14
  • 24
0

you have to add the missing local lang helper: for me the missing ones where de_LU de_LU.UTF-8 . Mongo 2.6.4 worked wihtout mongo 2.6.5 throw an error on this

cwhisperer
  • 1,478
  • 1
  • 32
  • 63