See Footnote below.
From the message:
System has not been booted with systemd as init system (PID 1). Can't operate.
... it appears that you are using Ubuntu 18.04 under Windows Subsystem for Linux. It's also possible that you could be using it under some other containerized system like Docker, but in that case you would most likely be using the official MongoDB docker image, rather than trying to install it directly.
Assuming WSL, there are a few things going on:
First, please note that, while 18.04 is currently still on-topic here, its standard support will end in just about 3 months. It is highly recommended that you go ahead and move to 22.04, where you will have 4+ years of continued support. After April, questions about 18.04 will no longer be on-topic here on Ask Ubuntu.
The error message itself is because a default installation of WSL does not currently run Systemd. Recently, Systemd support has been added to the latest releases of WSL, but it is not enabled by default. See this answer for the current status and instructions. However ...
I believe that you are using the official MongoDB release already, so that's good.
I don't believe you necessarily have to enable Systemd on WSL in order to run MongoDB. See the WSL docs for how to configure MongoDB on WSL. The docs are for Ubuntu 20.04 and MongoDB 5.x, but I believe the same steps should work (unconfirmed) on 18.04 and 6.x.
Essentially, this involves downloading and using an init.d
script for starting MongoDB without the need for Systemd. The script is part of the official MongoDB repository, which is why I'm assuming it will still work with 6.x.
Note that another good alternative, IMHO, rather than installing MongoDB directly on Ubuntu is to use Docker. To do this:
Install Docker Desktop for Windows, which includes WSL2 integration.
At the most basic level, you can then start MongoDB by simply running:
docker run --name some-mongo -d mongo
See the MongoDB Docker image for more information. You'll certainly need to learn how to use Docker as well, but if you are going to be doing development tasks with MongoDB (or anything else), it's highly recommended.
Footnote:
I'm going to go ahead and post an answer to try to save us some delay due to the asynchronous nature of comments. I'm basing this answer on the assumption that you are using Windows Subsystem for Linux. Several other communities members agree that this is the most likely situation. And thanks and credit to @ArturMeinild who brought this to my attention and already did some research on this before turning it over to me (since I'm the "WSL Guy" around here ;-).
ubuntu-support-status
to assess the security status of your actual install. Your question is still on-topic here, but consider how much security matters to you and the results of prior command. You're now using Ubuntu 18.04 LTS with LXDE (not Lubuntu). – guiverc Jan 17 '23 at 06:55