Failed to start mongod.service: Unit mongod.service not found
Solution 1:
I reinstalled mongod-org, since my data will still stay safe.
The problem was that my system couldn't find mongod.service when I ran sudo service mongod status
.
Running this fixed it and restored the service:
sudo systemctl enable mongod
Then all I had to do was copy my correct config to /etc/mongod.conf
and run
sudo service mongod restart
Solution 2:
This has worked for me.
-
Uninstall your mongo completely from your system:
sudo service mongod stop sudo apt-get purge mongodb-org* sudo rm -r /var/log/mongodb sudo rm -r /var/lib/mongodb
-
Now reinstall mongodb using following commands:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5 echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list sudo apt-get update sudo apt-get install -y mongodb-org
To install a specific release, you must specify each component package individually along with the version number, as in the following example:
sudo apt-get install -y mongodb-org=3.6.0 mongodb-org-server=3.6.0 mongodb-org-shell=3.6.0 mongodb-org-mongos=3.6.0 mongodb-org-tools=3.6.0
-
Now you can see mongod working but still the same issue is bothering you. The issue is that your system couldn't find mongod.service when you run
sudo service mongod status
.Running this fixed it and restored the service:
sudo systemctl enable mongod
-
Now you're all set to use mongo.
sudo service mongod restart
Solution 3:
I too faced the exact problem mentioned by OP, even though I installed Mongodb using the official install tutorial (https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/ ),
NOTE: in step 2 of the tutorial (create a list file for Mongodb), it is important to click on the tab specific to the particular version of Ubuntu on your machine. By default it shows Ubuntu 14.04, which created the problems mentioned by OP (Failed to start mongod.service: Unit mongod.service not found)
When I finally noticed that in step 2 I had to properly select Ubuntu 16.04 (for me), the install was successful and after this mongod ran without any issues.