Skip to content

Instantly share code, notes, and snippets.

@matinrco
Last active February 4, 2023 06:21
Show Gist options
  • Save matinrco/cdb3c0e5accc924b75c60b1648730867 to your computer and use it in GitHub Desktop.
Save matinrco/cdb3c0e5accc924b75c60b1648730867 to your computer and use it in GitHub Desktop.
Install MongoDB 4.4.1 on Windows 10 WSL 2 (Debian 10/Buster - Ubuntu 20.04 LTS (Focal Fossa))

Install MongoDB 4.4.1 on WSL 2 (Debian 10/Buster - Ubuntu 20.04 LTS (Focal Fossa))

Download these .deb files :

Download this init.d script and save to /etc/init.d/mongod

  • from official mongodb repo : link

  • Or with commands 👇😉

    sudo curl -o /etc/init.d/mongod https://raw.githubusercontent.com/mongodb/mongo/master/debian/init.d
    sudo chmod +x /etc/init.d/mongod

Install downloded deb files in this order with these commands

  1. Install mongodb-org-server :
    1. sudo dpkg --unpack mongodb-org-server_4.4.1_amd64.deb
    2. Edit /var/lib/dpkg/info/mongodb-org-server.postinst file and comment the line systemctl daemon-reload. then save and exit.
    3. Run sudo dpkg --configure mongodb-org-server
    4. done. now you can manage service by sudo service mongod start|stop|restart
  2. Install sudo dpkg -i mongodb-org-shell_4.4.1_amd64.deb
  3. Install sudo dpkg -i mongodb-org-mongos_4.4.1_amd64.deb
  4. Install sudo dpkg -i mongodb-org-database-tools-extra_4.4.1_amd64.deb
  5. Install sudo dpkg -i mongodb-database-tools_100.2.0_amd64.deb
  6. Install sudo dpkg -i mongodb-org-tools_4.4.1_amd64.deb
  7. Install sudo dpkg -i mongodb-org_4.4.1_amd64.deb

Done

  • Run sudo apt install -yf to fix any missing dependencies
  • You can verify installed packages by dpkg -l | grep mongodb
@matinrco
Copy link
Author

@matinrco Thank you for the link. Yes, I am aware, but the one in official ubuntu repos is mongodb version 3.6. I need version 4.* in order to use warch stream for database etc. . Unless you know a way to install latest 4.4 through the offical repo in ubuntu? looks like new versions need systemd which is not yet supporetd by WSL2

@ttfreeman
aha, I know, mongo 3 is kinda legacy...
I've just updated the gist with ubuntu links and it seems that it works fine now
to try it, first don't forget to remove any installed version of mongo or reset your wsl distro from windows setting then try again
(if you reset, all wsl disk content will be erased)

image

@ttfreeman
Copy link

Awesome! I'll check it out. I ended up using a docker-compose container but this would be more convenient for sure.

@omegapaulo
Copy link

@matinrco thank you mate, i've been looking for this for a year almost lol, you're a genius. The simplicity of this is out of this world. Thanks a bunch for real.

@matinrco
Copy link
Author

@omegapaulo , I'm glad it helped

@gutisalex
Copy link

gutisalex commented Jul 16, 2021

Hey, I am struggling to set this up!

First off:

$ lsb_release -a                                                                                                 ↵ 1
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 10 (buster)
Release:        10
Codename:       buster

I downloaded everything, unpacked the server and edited the mongodb-org-server.postinst file.

I try to install the server:

$ sudo dpkg --configure mongodb-org-server
Setting up mongodb-org-server (4.4.1) ...
invoke-rc.d: could not determine current runlevel

the server is installed:

$ dpkg -l | grep mongodb
ii  mongodb-org-server             4.4.1                                amd64        MongoDB database server

but trying to start gives me:

$ sudo service mongod start
[FAIL] Starting database: mongod failed!

Thats in the logs:

$ sudo cat /var/log/mongodb/mongod.log                                                                           ↵ 1

{"t":{"$date":"2021-07-16T13:48:58.552+02:00"},"s":"W",  "c":"CONTROL",  "id":20698,   "ctx":"main","msg":"***** SERVER RESTARTED *****","tags":["startupWarnings"]}
{"t":{"$date":"2021-07-16T13:48:58.552+02:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2021-07-16T13:48:58.556+02:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2021-07-16T13:48:58.556+02:00"},"s":"I",  "c":"NETWORK",  "id":4648601, "ctx":"main","msg":"Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize."}
{"t":{"$date":"2021-07-16T13:48:58.556+02:00"},"s":"I",  "c":"STORAGE",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":3108,"port":27017,"dbPath":"/var/lib/mongodb","architecture":"64-bit","host":"PC-Alex"}}
{"t":{"$date":"2021-07-16T13:48:58.556+02:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.1","gitVersion":"ad91a93a5a31e175f5cbf8c69561e788bbc55ce1","openSSLVersion":"OpenSSL 1.1.1d  10 Sep 2019","modules":[],"allocator":"tcmalloc","environment":{"distmod":"debian10","distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2021-07-16T13:48:58.556+02:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"PRETTY_NAME=\"Debian GNU/Linux 10 (buster)\"","version":"Kernel 5.4.72-microsoft-standard-WSL2"}}}
{"t":{"$date":"2021-07-16T13:48:58.556+02:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"config":"/etc/mongod.conf","net":{"bindIp":"127.0.0.1","port":27017},"processManagement":{"timeZoneInfo":"/usr/share/zoneinfo"},"storage":{"dbPath":"/var/lib/mongodb","journal":{"enabled":true}},"systemLog":{"destination":"file","logAppend":true,"path":"/var/log/mongodb/mongod.log"}}}}
{"t":{"$date":"2021-07-16T13:48:58.557+02: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"}}
{"t":{"$date":"2021-07-16T13:48:58.557+02:00"},"s":"F",  "c":"-",        "id":23091,   "ctx":"initandlisten","msg":"Fatal assertion","attr":{"msgid":40486,"file":"src/mongo/transport/transport_layer_asio.cpp","line":919}}
{"t":{"$date":"2021-07-16T13:48:58.557+02:00"},"s":"F",  "c":"-",        "id":23092,   "ctx":"initandlisten","msg":"\n\n***aborting after fassert() failure\n\n"}

Edit: I had to remove this file /tmp/mongodb-27017.sock

Now it works, big thanks for the tutorial!

@matinrco
Copy link
Author

matinrco commented Jul 16, 2021

Edit: I had to remove this file /tmp/mongodb-27017.sock

@gutisalex , Thanks for sharing the solution 👍

@omegapaulo
Copy link

@omegapaulo , I'm glad it helped

What's man, hope all is good with you.
I wanted to ask if this same tutorial would work to install mongodb version 5?
Thanks in advance.

@yct72
Copy link

yct72 commented Feb 4, 2023

Hope this will help someone who also fail on this: 🥲

$ sudo service mongod start
 * Starting database mongod                                                                                                              [fail]

I don't have /tmp/mongodb-27017.sock at this moment, it took me some time then I found this, seems that /var/run/mongod.pid was the problem.
simply solve it by sudo chown mongodb:mongodb /var/run/mongod.pid and it works! (If doesn't, try rm /tmp/mongodb-27017.sock as mentioned above again.)

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