40

I try to install mongo using mongo documentation: Install MongoDB on Ubuntu no errors were mentioned during the installation. But when I run the mongo command following error was displayed in the terminal.

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

89

Looks like your locale settings are broken or non-existent on that VM, or at least that session on that VM. One of MongoDB's dependencies (boost) will fail when a locale is not correctly set (see SERVER-9032). For reference, before the change in SERVER-9032 this problem still happened but looked like this.

Sometimes logging out and back in can fix it (only broken for current session), or you can try running sudo locale-gen to make sure generation is successful.

In the meantime, as a workaround to get mongo (or mongod etc.) running, just set your LC_ALL variable manually before starting the program:

export LC_ALL=C
mongo 
  • Are we supposed to configure the locale when creating a new VM? – Alex Jun 25 '15 at 12:29
  • 1
    Depends on how you do your OS install - most setup flows/UIs are going to take care of this for you by asking you where you are and what language you use - if you go old school you would have to potentially do this yourself, but I'm fairly sure I haven't seen a locale selection screen for years. Basically, it's not unreasonable to expect this to be done for you and you should only hear about it when it is screwed up in some way. – Adam C Jun 25 '15 at 17:41
  • Thanks, it was a CentOS Vm so i think I need an Ansible task for that! – Alex Jun 26 '15 at 7:56
15

I also tried installing MongoDB on Ubuntu 12.04 and got the same error on a virtual machine (XEN). For me, modifiying /etc/default/locale did the trick. I got it working with these settings:

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

Or, another working config would be (mind the quotes and the :en):

LANG="en_US.UTF-8"
LANGUAGE="en_US:en"
LC_ALL="en_US.UTF-8"

Adam C's workaround with export also helped and is probably the more elaborate answer.

4

Though the other answers provided here solve the problem correctly the following Stackoverflow question brought me to what the actual issue is when having MongoDB installed in a Vagrant VM and getting the above error:

This problem appears because host machine put locale to guest via ssh.

Thus the answer suggesting to override the host locale within the Vagrantfile solves it permanently with just a line:

Vagrant.configure(2) do |config|

    ENV['LC_ALL']="en_US.UTF-8"

    # ...

end

Also note the comments about that it does not modify the actual LC_ALL value on the host.

1

Based on this https://askubuntu.com/a/227513/59618 you can just:

$ sudo locale-gen "en_US.UTF-8"
Generating locales...
  en_US.UTF-8... done
Generation complete.

$ sudo dpkg-reconfigure locales
Generating locales...
  en_US.UTF-8... up-to-date
Generation complete.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.