Installing mongoDB the Painful Way

I am working on a Python project that requires a mongoDB backend. I used Visual Studio Code’s Remote – Containers extension to quickly spin up a Docker container with Python 3.6 and Node.js preconfigured…but there wasn’t a mongoDB option. No problem, I’ll install it myself.

I follow along with mongoDB’s instructions for installation using the system (in this case Debian) package manager. This is where I encounter my first problem. When I attempt to run sudo apt install mongodb-org I get errors regarding mongodb’s dependencies – e.g. mongodb-shell. There is some problem with libc, etc. I track this down for a bit and try upgrading libc. No luck.

Thankfully, I run across a UNIX StackExchange post “Cannot Install Git Because Libc6 Package is Broken“. @bk2204 points out “You’re using a PPA for Git for Ubuntu hirsuite, which is not the same as Debian buster.” Now some VSC containers do use Ubuntu and I had made the assumption that the Python container did as well – but it doesn’t. That would be my problem – I’m trying to follow mongoDB’s install instructions for Ubuntu when I’m actually using Debian (and yes, Ubuntu is based on Debian but that doesn’t count atm).

I run through the instructions for installation again and this time it throws another error at me, something like /var/lib/dpkg/info/mongodb-org-server.postinst: 43: /var/lib/dpkg/info/mongodb-org-server.postinst: systemctl: not found. Great. This time it is @Edward_Bordin who provides the answer on mongoDB’s forums:

ln -T /bin/true /usr/bin/systemctl && apt-get update && apt-get install -y mongodb-org && rm /usr/bin/systemctl

This tricks mongoDB into thinking it can access systemctl and once the install is completed removes the link that played pretend.

I try running mongodb: mongod. It starts up, spits out some logging and then shuts down. It is trying to open a database at a non-existent path. @Mehedi Abdullah comes to the rescue on StackOverflow responding to the question “When running Mongodb got NonExistentPath: Data directory /data/db not found., terminating“. The solution is easier than I’d imagined: sudo mkdir -p /data/db. That’s right, create an empty directory and Mongodb will stop whining.

I rerun mongod and this time it starts up and stays up.

Hope this saves someone some pain and my thanks to others who have gone before me and answered the individual questions. I spent a few hours on this (and some loosely associated problems) but could have spent many more if others hadn’t been so kind.

Leave a Reply