Skip to content

Install MongoDB in Windows Linux Subsystem #796

Closed

Description

@carpet92

I try to install MongoDB with this instructions from official website https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
sudo apt-get update
sudo apt-get install -y mongodb-org

After installation is complete I try to run mongodb with

sudo service mongod start

but have follow error

User@DESKTOP-TPQIRNP:/mnt/c/Users/User$ sudo service mongod start
initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused
mongod: unrecognized service

But If I install MongoDB with sudo apt-get install mongodb I can run it with sudo service mongodb start and this work. But with sudo apt-get install mongodb will be installed old 2.x.x version of MongoDB

How to install the latest stable version of MongoDB (3.x.x) without errors on Windows Linux Subsystem ?

Activity

  1. carpet92 commented on Aug 6, 2016

    @carpet92
    Author

    Xander Smeets (@XSmeets) services are unimplemented for now but if I install mongodb with sudo apt-get install mongodb sudo service mongod start will work

  2. carpet92 commented on Aug 6, 2016

    @carpet92
    Author

    Xander Smeets (@XSmeets) I wrote in my issue that everything is working fine (with install mongodb with sudo apt-get install mongodb and run sudo service mongodb start). You can check it yourself if you have Windows 10 with Linux Subsystem. And if you try to connect to MongoDB with Mongoose It will also work well. And about Upstart #791 (comment) I have problem only with install latest stable MongoDB from official instructions

  3. aseering commented on Aug 6, 2016

    @aseering
    Contributor

    Xander Smeets (@XSmeets) -- you are technically correct that Upstart is responsible for starting applications, but not in the way that you imply here. The service command doesn't call Upstart. Quite the opposite -- Upstart calls the service command when your machine boots.

    The absence of Upstart means that mongodb will not automatically start on reboot; @Zx-EvM will have to re-run sudo service mongodb start to start using MongoDB again. However, it works just fine otherwise.

    nginx and OpenSSH both do fail currently, but not because of Upstart. nginx fails due to an issue related to IPv6 support; see #68 for details and a workaround. OpenSSH fails due to lack of chroot support among other issues; there's discussion on #300 , and the workaround is documented on this forum post. In both cases, the failures are not due to issues involving Upstart.

  4. carpet92 commented on Aug 6, 2016

    @carpet92
    Author

    Adam Seering (@aseering)

    will have to re-run sudo service mongodb start to start using MongoDB again

    Yes. I understand it. but my issue is that for some reason does not work correctly MongoDB (not run) after install as here https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

  5. rodrymbo commented on Aug 6, 2016

    @rodrymbo

    If you get the initctl error message about not being able to talk to upstart, and the service doesn't start, you might want to look for the script in /etc/init.d, which is (usually) a standard bash script. Run it like any other bash script, with start as a parameter. In other words, remove the word "service" from the command and call the script by its full path. Then it won't matter if upstart or service isn't implemented fully.

    I've been doing that with sshd, sudo /etc/init.d/ssh start rather than sudo service ssh start . Note that the script is not called sshd, as you might expect.

    Your mileage may vary, and there may not be a bash script in /etc/init.d you can run.

    If you run the script and then it reports an error, you can be sure it is an error in that script or in the way your service runs. Right now, invoking it with the service command, before services are supported, it's hard to say where the problem is.

    The other option is to find the executable for the service/daemon's executable. Frequently there is a way to make it run from a command line (usually for testing, or special applications). That's even more simple than running it from a bash script. If you can get the executable running that way, you can work from there to getting a script working.

    Just a comment: right now we are using WSL when many things are broken or not yet implemented. Yes, we all know sudo service mongodb start is the proper way to start it, but since services aren't yet implemented, and we want to get some work done, we look for workarounds. Similarly, if there is a problem getting mongodb runniing in its barest, cleanest implementation, it may be helpful for it to be reported to the WSL folks separate from the issue of not being able to run it as a service.

  6. carpet92 commented on Aug 6, 2016

    @carpet92
    Author

    rodrymbo thanks. If I run MongoDB (which installed using sudo apt-get install mongodb not latest) with sudo /etc/init.d/mongodb start this work without initctl error message. Hm. But if I install MongoDB using official instruction

    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
    echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
    sudo apt-get update
    sudo apt-get install -y mongodb-org
    

    I don't even have any file related mongodb in /etc/init.d directory.

  7. rodrymbo commented on Aug 6, 2016

    @rodrymbo

    I'm not familiar enough with upstart or mongodb (yet) to speculate too much.

    If you use the first method (sudo apt-get install mongodb, without implementing the repository at repo.mongodb.org), and you do get the mongodb script in /etc/init.d, you could save a copy of it somewhere like your home directory. It will include a line somewhere that does the actual starting of the mongod daemon (most likely). Then if you install from the repo.mongodb.org repository, there's a chance the script you saved may work. If not it may give you clues as to where to find the executable, or what to use in man to learn about it, for example, how to run it without it detaching or becoming a daemon (perhaps -D). I'd guess the daemon executable is mongod, but it's only a guess.

  8. aseering commented on Aug 6, 2016

    @aseering
    Contributor

    @Zx-EvM -- ah, sorry, I confused your two recent posts.

    It looks like the new package really is an Upstart-specific script. That means that you don't start it using sudo service mongod start; you start it with sudo /sbin/start mongod. Which doesn't appear to work right now.

    Oddly, though, if I install the old version and then (without removing it) I install the new version, then sudo service mongodb start (which is a script installed by the old package) seems to detect the new version of mongodb instead of the old one, and start it correctly.

    $ sudo service mongodb start
    initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused
     * Starting database mongodb                                                                                     [ OK ]
    $ mongo
    MongoDB shell version: 3.2.8
    connecting to: test
    2016-08-06T17:01:59.123-0400 E NETWORK  [thread1] can't get TCP_KEEPIDLE: errno:22 Invalid argument
    2016-08-06T17:01:59.123-0400 E NETWORK  [thread1] can't get TCP_KEEPINTVL: errno:22 Invalid argument
    > db.version()
    3.2.8
    >
    
  9. carpet92 commented on Aug 6, 2016

    @carpet92
    Author

    Adam Seering (@aseering) oh. Thanks! It's work for me

  10. KEMDAK commented on Aug 6, 2016

    @KEMDAK

    Adam Seering (@aseering) That worked :D thanks.

  11. aseering commented on Aug 10, 2016

    @aseering
    Contributor

    Incidentally, if anyone reading this wants to start mongodb at system start, I've posted a comment on these sshd instructions that I think explains how to do so:

    http://wsl-forum.qztc.io/viewtopic.php?f=6&t=10

  12. bschwartz757 commented on Sep 17, 2016

    @bschwartz757

    Hey! Sorry, but I'm a bit of a noob and I'm not quite able to to follow all of the instructions you guys have laid out. Is there any way one of you can post an exact set of commands for downloading and getting MongoDb running on WSL? I tried this:
    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927 echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list sudo apt-get update sudo apt-get install -y mongodb-org

    which threw an error, so I tried again with:
    sudo service mongodb start

    and it's still failing to install. Here's the output of that command:
    Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --homedir /tmp/tmp.wjm2zfd5JA --no-auto-check-trustdb --trust-model always --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927 echo deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse gpg: "echo" not a key ID: skipping gpg: "deb" not a key ID: skipping gpg: "http://repo.mongodb.org/apt/ubuntu" not a key ID: skipping gpg: "trusty/mongodb-org/3.2" not a key ID: skipping gpg: "multiverse" not a key ID: skipping gpg: requesting key EA312927 from hkp server keyserver.ubuntu.com gpg: key EA312927: public key "MongoDB 3.2 Release Signing Key <[email protected]>" imported gpg: Total number processed: 1 gpg: imported: 1 (RSA: 1)

    Many thanks!!

  13. acezard commented on Sep 18, 2016

    @acezard

    blake schwartz (@bschwartz757) the only way I managed to make MongoDB works on WSL was to install an old version. sudo apt-get install mongodb on a clean installation. Then just launching sudo mongod. I was unable to use the latest version due to wiredTiger issues

  14. bschwartz757 commented on Sep 18, 2016

    @bschwartz757

    Ah, dang, that's too bad. I'm doing the Mongo University course right now and thought it might be useful to have a working Mongo instance on WSL, but it wouldn't really make sense to do so with an old version.

    I guess I'll have to stick with Git Bash for now. Thanks for the response!

  15. bschwartz757 commented on Sep 20, 2016

    @bschwartz757

    Adam Seering (@aseering) how did you actually manage to install the new version, if I might ask? I was able to install using the apt-get command others referenced, but I have version 2.4.9 now. Interested in trying out the solution you mentioned.

    Thanks Antonin Cezard (@acezard) I was able to install the old version as you suggested. Still can't get it to run though...

  16. 27 remaining items

  17. benjaminbauer commented on Jun 4, 2018

    @benjaminbauer

    therealkenc Thanks a lot for the hint!
    You mean sudo mongod --fork --config /etc/mongod.conf, right?

  18. therealkenc commented on Jun 4, 2018

    @therealkenc

    You mean sudo mongod --fork --config /etc/mongod.conf, right?

    Correct. Bad combination of typing and then changing mind and pasting what was actually in my terminal. I've fixed up the post. Or even more correctly, "whatever works", laugh.

  19. Mikeysax commented on Jun 10, 2018

    @Mikeysax
  20. MajidJafari commented on Dec 20, 2018

    @MajidJafari

    I had also problem installing mongodb on wsl. You might check my answer on another issue related to this one:
    https://github.com/Microsoft/WSL/issues/3286#issuecomment-449053033

  21. gigamesh commented on Mar 7, 2019

    @gigamesh

    Michael Farrell (@Mikeysax) Thanks a lot for that tutorial! It helped me get everything working but I'm getting "WARNING: shell and server versions do not match" (shell version v4.0.6, server version: 3.6.3). Restarting the service doesn't work. Any ideas?

  22. nevergiveup777 commented on Jun 2, 2019

    @nevergiveup777

    I had the same problem to install MongoDB on Ubuntu 18.04 (WSL) and I sorted out by just running:

    sudo apt-get install mongodb

    Not sure why this solution wasn't commented before.

    Source: https://medium.com/@zhanxucong/installing-mongodb-and-redis-on-wsl-2038a2f6a0a9

  23. therealkenc commented on Jun 2, 2019

    @therealkenc

    Not sure why this solution wasn't commented before.

    [a.] It was (quoth: "The other way to go is use Ubuntu's mongodb") and [b.] The ask was for mongodb-org not mongodb. This issue wouldn't even be on the books if the ask was mongodb.

  24. Roaim commented on Apr 9, 2020

    @Roaim

    I was able to fix it by performing following tasks:

    sudo nano /etc/init.d/mongod
    

    then copy and paste the content from this url and save it (you can use vim or any other text editor)

    After that give executable permission

    sudo chmod +x /etc/init.d/mongod
    

    Now you will be able to start the service by following command

    sudo service mongod start
    
  25. ais-one commented on Apr 19, 2020

    @ais-one

    I was able to fix it by performing following tasks:

    sudo nano /etc/init.d/mongod
    

    then copy and paste the content from this url and save it (you can use vim or any other text editor)

    After that give executable permission

    sudo chmod +x /etc/init.d/mongod
    

    Now you will be able to start the service by following command

    sudo service mongod start
    

    This is correct. Somehow for the mongodb-org package (the package described in MongoDB documentation) on WSL Ubuntu (tried on 18.04), the service is not created.

    If you use sudo apt-get install mongodb you are actually installing and using a different package which may not have an updated version of MongoDB.

  26. bn-l commented on Feb 1, 2021

    @bn-l

    I was able to fix it by performing following tasks:

    sudo nano /etc/init.d/mongod
    

    then copy and paste the content from this url and save it (you can use vim or any other text editor)

    After that give executable permission

    sudo chmod +x /etc/init.d/mongod
    

    Now you will be able to start the service by following command

    sudo service mongod start
    

    I tried this and got this:

    fail

  27. ais-one commented on Feb 6, 2021

    @ais-one

    I had moved on to using Docker. Since Docker works well with WSL on Windows Home Edition 2004

  28. Roaim commented on Feb 6, 2021

    @Roaim

    I was able to fix it by performing following tasks:

    sudo nano /etc/init.d/mongod
    

    then copy and paste the content from this url and save it (you can use vim or any other text editor)
    After that give executable permission

    sudo chmod +x /etc/init.d/mongod
    

    Now you will be able to start the service by following command

    sudo service mongod start
    

    I tried this and got this:

    fail

    I was able to fix it by performing following tasks:

    sudo nano /etc/init.d/mongod
    

    then copy and paste the content from this url and save it (you can use vim or any other text editor)
    After that give executable permission

    sudo chmod +x /etc/init.d/mongod
    

    Now you will be able to start the service by following command

    sudo service mongod start
    

    I tried this and got this:

    fail

    Actually, you need to install mongodb first then create the service script. Did you follow this tutorial,

    https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu

    to install mongodb before trying my suggested workaround?

  29. ais-one commented on Feb 7, 2021

    @ais-one

    This article may help. There are 2 packages for ubuntu... mongodb (not sure who created this) and mongodb-org (official). It explains which to use in a little more detail.

    https://dev.to/zenika/setup-mongodb-on-wsl-ubuntu-18-04-167

  30. Scribblets commented on Feb 12, 2021

    @Scribblets

    I was able to fix it by performing following tasks:

    sudo nano /etc/init.d/mongod
    

    then copy and paste the content from this url and save it (you can use vim or any other text editor)
    After that give executable permission

    sudo chmod +x /etc/init.d/mongod
    

    Now you will be able to start the service by following command

    sudo service mongod start
    

    I tried this and got this:
    fail

    I was able to fix it by performing following tasks:

    sudo nano /etc/init.d/mongod
    

    then copy and paste the content from this url and save it (you can use vim or any other text editor)
    After that give executable permission

    sudo chmod +x /etc/init.d/mongod
    

    Now you will be able to start the service by following command

    sudo service mongod start
    

    I tried this and got this:
    fail

    Actually, you need to install mongodb first then create the service script. Did you follow this tutorial,

    https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu

    to install mongodb before trying my suggested workaround?

    I am having this issue too, and I installed mongodb before this. Still getting this fail, and I cannot find anything on how to fix or get the server running.

  31. imjxydhh commented on Jun 9, 2022

    @imjxydhh

    I was able to fix it by performing following tasks:

    sudo nano /etc/init.d/mongod
    

    then copy and paste the content from this url and save it (you can use vim or any other text editor)
    After that give executable permission

    sudo chmod +x /etc/init.d/mongod
    

    Now you will be able to start the service by following command

    sudo service mongod start
    

    I tried this and got this:
    fail

    I was able to fix it by performing following tasks:

    sudo nano /etc/init.d/mongod
    

    then copy and paste the content from this url and save it (you can use vim or any other text editor)
    After that give executable permission

    sudo chmod +x /etc/init.d/mongod
    

    Now you will be able to start the service by following command

    sudo service mongod start
    

    I tried this and got this:
    fail

    Actually, you need to install mongodb first then create the service script. Did you follow this tutorial,
    https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu
    to install mongodb before trying my suggested workaround?

    I am having this issue too, and I installed mongodb before this. Still getting this fail, and I cannot find anything on how to fix or get the server running.

    Check the log file (should be /var/log/mongod.log), if there is something like this,

    {"t":{"$date":"2022-06-09T09:48:22.057+08:00"},"s":"E",`  "c":"NETWORK",  "id":23024,   "ctx":"initandlisten","msg":"Failed to unlink socket file","attr":{"path":"/tmp/mongodb-27017.sock","error":"Operation not permitted"}}
    

    Try deleting /tmp/mongodb-27017.sock or change the owner of this file to user mongodb. This works for me.

    It may be because of running mongodb manually with mongod command as other users. and the file was created by that user, which causes the mongodb's default user mongodb can not access this file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions