Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install MongoDB in Windows Linux Subsystem #796

Closed
carpet92 opened this issue Aug 6, 2016 · 54 comments
Closed

Install MongoDB in Windows Linux Subsystem #796

carpet92 opened this issue Aug 6, 2016 · 54 comments

Comments

@carpet92
Copy link

carpet92 commented Aug 6, 2016

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 ?

@carpet92
Copy link
Author

carpet92 commented Aug 6, 2016

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

@carpet92
Copy link
Author

carpet92 commented Aug 6, 2016

@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

@aseering
Copy link
Contributor

aseering commented Aug 6, 2016

@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.

@carpet92
Copy link
Author

carpet92 commented Aug 6, 2016

@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/

@rodrymbo
Copy link

rodrymbo commented Aug 6, 2016

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.

@carpet92
Copy link
Author

carpet92 commented Aug 6, 2016

@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.

@rodrymbo
Copy link

rodrymbo commented Aug 6, 2016

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.

@aseering
Copy link
Contributor

aseering commented Aug 6, 2016

@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
>

@carpet92
Copy link
Author

carpet92 commented Aug 6, 2016

@aseering oh. Thanks! It's work for me

@KEMDAK
Copy link

KEMDAK commented Aug 6, 2016

@aseering That worked :D thanks.

@aseering
Copy link
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

@bschwartz757
Copy link

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!!

@acezard
Copy link

acezard commented Sep 18, 2016

@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

@bschwartz757
Copy link

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!

@bschwartz757
Copy link

@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 @acezard I was able to install the old version as you suggested. Still can't get it to run though...

@aseering
Copy link
Contributor

Hi @bschwartz -- I just installed the old version from Ubuntu "apt", then added the repository containing the new version and installed that.

That was several versions of WSL ago, though. Maybe there has been a relevant change or regression?

@sunilmut
Copy link
Member

Has anyone been able to get the MongoDB version 3.2.9 working on WSL? After following the instructions from @Zx-EvM, I was able to get 3.2.9 installed. service mongodb start is fine, but then service mongodb status shows fail.

@kpobococ
Copy link

This is not a WFL problem, the problem is with Ubuntu 14.04:

@bschwartz757
Copy link

@anton @aseering Huh... I followed the steps on the installation guide and
it seems have gotten v3.2.9 installed. Only problem is that now I get
errors when attempting mongod or the shell, and it is unusable. Specifying
a dbpath and port was working for me previously with 2.4.9 but no love
here, unfortunately:

root@blakes-PC:/mnt/c/Windows/System32# mongod --dbpath /mnt/c/data/db/
--port 39019
2016-09-21T06:36:29.325-0700 I CONTROL [initandlisten] MongoDB starting :
pid=780 port=39019 dbpath=/mnt/c/data/db/ 64-bit host=blakes-PC
2016-09-21T06:36:29.326-0700 I CONTROL [initandlisten] db version v3.2.9
2016-09-21T06:36:29.326-0700 I CONTROL [initandlisten] git version:
22ec9e93b40c85fc7cae7d56e7d6a02fd811088c
2016-09-21T06:36:29.326-0700 I CONTROL [initandlisten] OpenSSL version:
OpenSSL 1.0.1f 6 Jan 2014
2016-09-21T06:36:29.326-0700 I CONTROL [initandlisten] allocator: tcmalloc
2016-09-21T06:36:29.326-0700 I CONTROL [initandlisten] modules: none
2016-09-21T06:36:29.326-0700 I CONTROL [initandlisten] build environment:
2016-09-21T06:36:29.326-0700 I CONTROL [initandlisten] distmod:
ubuntu1404
2016-09-21T06:36:29.326-0700 I CONTROL [initandlisten] distarch: x86_64
2016-09-21T06:36:29.327-0700 I CONTROL [initandlisten] target_arch:
x86_64
2016-09-21T06:36:29.327-0700 I CONTROL [initandlisten] options: { net: {
port: 39019 }, storage: { dbPath: "/mnt/c/data/db/" } }
2016-09-21T06:36:29.349-0700 I - [initandlisten] Detected data files
in /mnt/c/data/db/ created by the 'wiredTiger' storage engine, so setting
the active storage engine to 'wiredTiger'.
2016-09-21T06:36:29.353-0700 I STORAGE [initandlisten] wiredtiger_open
config:
create,cache_size=1G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2016-09-21T06:36:30.196-0700 E STORAGE [initandlisten] WiredTiger (5)
[1474464990:196582][780:0x7fa0d5450cc0], WT_SESSION.checkpoint:
/mnt/c/data/db//journal: handle-sync: fdatasync: Input/output error
2016-09-21T06:36:30.198-0700 E STORAGE [initandlisten] WiredTiger (5)
[1474464990:198196][780:0x7fa0d5450cc0], txn-recover: Recovery failed:
Input/output error
2016-09-21T06:36:30.702-0700 E STORAGE [initandlisten] WiredTiger (5)
[1474464990:702478][780:0x7fa0d5450cc0], connection:
/mnt/c/data/db//journal: handle-sync: fdatasync: Input/output error
2016-09-21T06:36:30.703-0700 E STORAGE [initandlisten] WiredTiger (0)
[1474464990:704083][780:0x7fa0d5450cc0], connection: Connection has open
file handles: journal
2016-09-21T06:36:30.704-0700 I - [initandlisten] Assertion: 28595:5:
Input/output error
2016-09-21T06:36:30.704-0700 I STORAGE [initandlisten] exception in
initAndListen: 28595 5: Input/output error, terminating
2016-09-21T06:36:30.704-0700 I CONTROL [initandlisten] dbexit: rc: 100
root@blakes-PC:/mnt/c/Windows/System32#

  • Blake Schwartz

On Wed, Sep 21, 2016 at 4:39 AM, Anton Suprun [email protected]
wrote:

This is not a WFL problem, the problem is with Ubuntu 14.04:


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#796 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AHK9nPxxPYEPFxF0pux2Ot1pAAoOj3gjks5qsReGgaJpZM4JeViz
.

@acezard
Copy link

acezard commented Sep 21, 2016

@bschwartz757 : try deleting the db folder and recreating it.

Installing the 3.2.9 was fine for me, but it was crashing after 1 minute because of an issue with wired tiger ('function non implemented')

@bschwartz757
Copy link

Thanks Antonin... My only concern is, that folder is currently not empty on
the Windows side of my machine as I'm currently working on a Mongo
University course. There's nothing particularly valuable in there but I
assume that wiping it out on one will have the net effect of wiping it out
on both. So it sounds like I'll have to choose between running it on
Windows with the limitations (but familiarity) that entails, and running it
on Linux.

  • Blake Schwartz

On Wed, Sep 21, 2016 at 8:27 AM, Antonin Cezard [email protected]
wrote:

@bschwartz757 https://github.com/bschwartz757 : try deleting the db
folder and recreating it.

Installing the 3.2.9 was fine for me, but it was crashing after 1 minute
because of an issue with wired tigers ('function non implemented')


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#796 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AHK9nKgawFa6kFVRGrC2RGUSl-yNSeuYks5qsUzngaJpZM4JeViz
.

@bschwartz757
Copy link

Looks like I finally have a working installation!! Thanks all for your help and input. I renamed my windows data/ directory to data_bak/ and things seem to be working now... I even ran a shell script provided by the Mongo University course to create a replica set using the Linux --fork option and it looks like they are all up and running. Connecting with a mongo shell also shows v3.2.

I'll keep my fingers crossed that nothing blows up in my face, but this looks like a good sign!

@darkdragon-001
Copy link

I got it working with your instructions, too.

Note that the service is called mongodb instead of mongod for my installation (as it was in the Ubuntu 14.04 version).

@bschwartz757
Copy link

Just installed the latest round of updates; running mongodb service works fine but when I try to run the mongo shell it causes a blue screen with an error and restarts my computer. Mongodb on the windows side seems to work fine, so I'll go back to that for now. The annoying thing is I was just getting used to being able to use all the handy linux programs while in the shell, now I'm back to git bash and it's "warning: terminal is not fully functional" messages if I try to use vim, less, etc.

@benhillis
Copy link
Member

Fear not, the fix is coming soon!

@bschwartz757
Copy link

Excellent! Seemed like I was able to do most things I wanted with MongoDB
and I was really enjoying the shell experience. Thanks for the great work!

  • Blake Schwartz

On Sun, Oct 2, 2016 at 3:46 PM, Ben Hillis [email protected] wrote:

Fear not, the fix is coming soon!


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#796 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AHK9nLkjIdGluD9sB2z7lneqGJ3HBkMmks5qwDQtgaJpZM4JeViz
.

@sulliwane
Copy link

I added mongodb-org repo, apt-get install -y --force-yes mogodb-org and then started mongod with mongod --dbpath /mnt/c/windows/fs/mongodb, I get this error from wiredTiger:

WiredTiger (5) [1475891848:14284][16853:0x7fb221910cc0], connection: /mnt/c/mongodb-linux-x86_64-ubuntu1404-3.2.10/bin/data/db/: directory-sync: fdatasync: Input/output error
2016-10-08T09:57:28.017+0800 I -        [initandlisten] Assertion: 28595:5: Input/output error
2016-10-08T09:57:28.018+0800 I STORAGE  [initandlisten] exception in initAndListen: 28595 5: Input/output error, terminating
2016-10-08T09:57:28.018+0800 I CONTROL  [initandlisten] dbexit:  rc: 100

If I start mongodb with dbpath pointing to linux filesystem, then no problem

@yuri-stepanov
Copy link

Hello there.
Just wanted to add, that still having an error
mongod: unrecognized service, after fresh installing on a
Distributor ID: Ubuntu Description: Ubuntu 16.04.3 LTS Release: 16.04 Codename: xenial WSL
Regular Ubuntu fine though..

@Zeioth
Copy link

Zeioth commented Aug 29, 2017

You can solve this issue "copy-pasting" this bash script

set -e
if grep -qE "(Microsoft|WSL)" /proc/version &> /dev/null ; then
    sudo apt-get install -y curl
    sudo rm -f /etc/init/mongodb.conf
    sudo curl --http1.1 https://raw.githubusercontent.com/mongodb/mongo/985e2a0be95709ac064c57f0a9bb385a55937285/debian/init.d --output /etc/init.d/mongod
    sudo chmod 755 /etc/init.d/mongod
    sudo mkdir -p /data/db
    sudo chown -R mongodb:mongodb /data/db
fi

@sunilmut
Copy link
Member

On the latest Insider build 16273, I am able to:

apt install -y mongodb
mkdir /data/db
mongod

And, I can see the mongodb service listening on port 27017.

@ghost
Copy link

ghost commented Sep 8, 2017

@Zeioth 's script resolved the issue for me.

Windows 10 Pro insider Preview
Version 1703
OS Build 16281.1000

@xtianus79
Copy link

Ok you shouldn't have to install the script any differently other than these few changes.... and you shouldn't have to make a directory... it's super odd to have to do it this way and where the break down is occurring I do not know but i will give instructions on how to install everything correctly at this time.

IMHO this is a large pile of hoo-diddy from someone and changes should be made... /rant.

Oh by the way, this is where i am altering the directions from....
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

first I purged my mongo so I know everything is from scratch w/ this command:
sudo apt-get purge mongodb-org*

  1. sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
  2. ubuntu 16.04:
    echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
  3. sudo apt-get update
  4. ***Not in mongo's directions: but rather something i got from reading above comments:
    sudo apt-get install mongodb
    ***At this point the version installed by mongo is an older version... for me ie.
mongod --version                                                                                                                             
db version v2.6.10
  1. sudo apt-get install -y mongodb-org
    ***Now, everything is installed correctly
mongod --version                                                                                                                             
db version v3.4.9
git version: 876ebee8c7dd0e2d992f36a848ff4dc50ee6603e
OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1604
    distarch: x86_64
    target_arch: x86_64

  1. ***Lastly, per the op's @Zx-EvM && @aseering above states that instead of the start command of mongod you would use the following command to start mongo:
    sudo service mongodb start

So what does this do in summary?

It installs mongod DB on an ubuntu 16.0.4 linux Windows subsystem... Updates it... and runs it via the start command... hope this helps someone and everything in this thread was awesome but a little verbose and not to the point which is what this summary is for.

@aankasman
Copy link

I have tried tips from @xtianus79 and it worked well. Here's what I did,

  1. me@Home-PC:~$ sudo apt-get purge mongodb-org*
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    Note, selecting 'mongodb-org-unstable-tools' for glob 'mongodb-org*'
    Note, selecting 'mongodb-org-mongos' for glob 'mongodb-org*'
    Note, selecting 'mongodb-org-tools' for glob 'mongodb-org*'
    Note, selecting 'mongodb-org-unstable-server' for glob 'mongodb-org*'
    Note, selecting 'mongodb-org-unstable-shell' for glob 'mongodb-org*'
    Note, selecting 'mongodb-org-shell' for glob 'mongodb-org*'
    Note, selecting 'mongodb-org-unstable-mongos' for glob 'mongodb-org*'
    Note, selecting 'mongodb-org-unstable' for glob 'mongodb-org*'
    Note, selecting 'mongodb-org' for glob 'mongodb-org*'
    Note, selecting 'mongodb-org-server' for glob 'mongodb-org*'
    Package 'mongodb-org-unstable' is not installed, so not removed
    Package 'mongodb-org-unstable-mongos' is not installed, so not removed
    Package 'mongodb-org-unstable-server' is not installed, so not removed
    Package 'mongodb-org-unstable-shell' is not installed, so not removed
    Package 'mongodb-org-unstable-tools' is not installed, so not removed
    Package 'mongodb-org' is not installed, so not removed
    Package 'mongodb-org-mongos' is not installed, so not removed
    Package 'mongodb-org-server' is not installed, so not removed
    Package 'mongodb-org-shell' is not installed, so not removed
    Package 'mongodb-org-tools' is not installed, so not removed
    The following package was automatically installed and is no longer required:
    snap-confine
    Use 'sudo apt autoremove' to remove it.
    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Then following steps took place

  1. me@Home-PC:~$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
    Executing: /tmp/tmp.6onMrC2S0j/gpg.1.sh --keyserver
    hkp://keyserver.ubuntu.com:80
    --recv
    0C49F3730359A14518585931BC711F9BA15703C6
    gpg: requesting key A15703C6 from hkp server keyserver.ubuntu.com
    gpg: key A15703C6: public key "MongoDB 3.4 Release Signing Key [email protected]" imported
    gpg: Total number processed: 1
    gpg: imported: 1 (RSA: 1)

  2. me@Home-PC:~$ echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse

  3. me@Home-PC:~$ sudo apt-get update
    Ign:1 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 InRelease
    Get:2 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
    Get:3 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 Release [3,457 B]
    Hit:4 https://deb.nodesource.com/node_7.x xenial InRelease
    Ign:5 https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 InRelease
    Hit:6 https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 Release
    Get:7 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 Release.gpg [801 B]
    Hit:8 http://archive.ubuntu.com/ubuntu xenial InRelease
    Get:10 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
    Get:11 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4/multiverse amd64 Packages [8,276 B]
    Get:12 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4/multiverse arm64 Packages [8,284 B]
    Fetched 225 kB in 8s (25.7 kB/s)
    Reading package lists... Done

  4. me@Home-PC:~$ sudo apt-get install mongodb
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    mongodb is already the newest version (1:2.6.10-0ubuntu1).
    The following package was automatically installed and is no longer required:
    snap-confine
    Use 'sudo apt autoremove' to remove it.
    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

  5. me@Home-PC:~$sudo service mongodb start

  • Starting database mongodb
  1. me@Home-PC:~$ mongod --version
    db version v2.6.10 2017-12-20T01:41:55.949+0700 git version: nogitversion 2017-12-20T01:41:55.950+0700 OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016

And finally get worked as resulted below 💯

  1. me@Home-PC:~$ mongo
    MongoDB shell version: 2.6.10
    connecting to: test
    Welcome to the MongoDB shell.
    For interactive help, type "help".
    For more comprehensive documentation, see
    http://docs.mongodb.org/
    Questions? Try the support group
    http://groups.google.com/group/mongodb-user
  2. exit
    bye
    me@Home-PC:~$

@therealkenc
Copy link
Collaborator

therealkenc commented May 30, 2018

MongoDB proper is operable on recent WSL following the canonical install instructions verbatim. On Ubuntu 16.04 (the most recent cited in the instructions) and 17672....

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
sudo apt-get update
sudo apt-get install -y mongodb-org
mongod --version

Yields:

db version v3.6.5
git version: a20ecd3e3a174162052ff99913bc2ca9a839d618
OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1604
    distarch: x86_64
    target_arch: x86_64

The remaining gap is that we don't have systemd, which causes the postinstall script to fail softly and silently. As a result, sudo service mongod fails with unrecognized service. I tried the exact sequence above in a Xenial VM and the mongod service is available. There is a related discussion here with a proposed solution. Or you can just start the thing manually.

sudo /usr/bin/mongod --fork --config /etc/mongod.conf

The other way to go is use Ubuntu's mongodb, which is patched to be a little friendlier about (lets call it) legacy init scripts. sudo apt install mongodb. In this case service mongodb start (sic with a 'b') takes. But the OP in this issue# was about installing mondodb-org's package, and Ubuntu's version might or might not be how you want to roll.

Postinstall scripts that depend on the existence of a functioning systemd is a different kettle of fish and not specific to mongodb. If anyone does find further issues with mongodb (like #645), please do feel encouraged to open a new issue.

@benjaminbauer
Copy link

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

@therealkenc
Copy link
Collaborator

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.

@Mikeysax
Copy link

For anyone wondering how to get the latest mongodb-org working with WSL:
https://gist.github.com/Mikeysax/cc86c30903727c556bcce960f7e4d59b

@MajidJafari
Copy link

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

@gigamesh
Copy link

gigamesh commented Mar 7, 2019

@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?

@nevergiveup777
Copy link

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

@therealkenc
Copy link
Collaborator

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.

@Roaim
Copy link

Roaim commented Apr 9, 2020

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

@ais-one
Copy link

ais-one commented Apr 19, 2020

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.

@bn-l
Copy link

bn-l commented Feb 1, 2021

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

@ais-one
Copy link

ais-one commented Feb 6, 2021

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

@Roaim
Copy link

Roaim commented Feb 6, 2021

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?

@ais-one
Copy link

ais-one commented Feb 7, 2021

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

@Scribblets
Copy link

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.

@imjxydhh
Copy link

imjxydhh commented Jun 9, 2022

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests