init script for mongodb 4 on WSL in ubuntu 18.04

If you try to start mongodb on WSL using systemd you will be getting this error.

System has not been booted with systemd as init system (PID 1). Can’t operate.

There seems to be no init script for mongodb 4 on ubuntu 18.04(may be other versions too). This makes it complicated for starting mongodb in WSL as systemctl is not supported on WSL. Inorder to have a init script so that you can start using service mongodb start we need to have the init file.

Thankfully init file is already provivided by mongodb here

https://raw.githubusercontent.com/mongodb/mongo/master/debian/init.d

Follow the below steps to get the mongodb running on WSL

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

This should successfully start mongodb.

Njoy smile


Comments

Let's discuss now…

This site uses Akismet to reduce spam. Learn how your comment data is processed.