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