52

I installed MongoDB 2.6 on clean installed Ubuntu 15.04:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update
sudo apt-get install -y mongodb-org

It finished without any problems. However, when I tried to start it, I got the following error:

$ sudo service mongod start
Failed to start mongod.service: Unit mongod.service failed to load: No such file or directory.

How can I fix this?

13 Answers13

65

I installed from the debian wheeze repository and it works fine.

First make sure you remove the mongodb-org package and all its dependencies:

sudo apt-get purge mongodb-org
sudo apt-get autoremove

Remove the old mongodb.list you created:

sudo rm /etc/apt/sources.list.d/mongodb.list

Use the Debian repository instead:

echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list

Update and install again:

sudo apt-get update
sudo apt-get install -y mongodb-org

After that, you can succesffully start the server:

sudo service mongod start

or

systemctl start mongod

(as clarified by Ernie Hershey in reply to Roman Gaufman's comment here: https://jira.mongodb.org/browse/SERVER-17742)

Dielson Sales
  • 1,178
  • 1
  • 8
  • 16
24

The MongoDB team says they won't support Ubuntu 15.04 and plan to support 16.04 instead (see https://jira.mongodb.org/browse/SERVER-17742).

Ubuntu 15.04 advances the default init system from Upstart to systemd. I had no success starting MongoDB 3.0 with systemd.

You can switch back to Upstart by installing upstart-sysv:

sudo apt-get install upstart-sysv

Then reboot and MongoDB should be up.

I hope to find an easy way to run MongoDB on Ubuntu 15.04 without switching things back in time.

Zippo
  • 353
4

You're installing from the packages published directly from mongodb.org. You should be installing from the packages supplied in the Ubuntu respository. The Debian/Ubuntu packages have been patched with systemd service units, to fill the hole left by mongodb.org.

(There's no shortage of mongodb.service unit files on the WWW. It's not hard to write one, either. I have.)

Specifically: you'll find such a service unit in the mongodb-server version 2.6 package for Ubuntu version 15. So just install that package.

(Note that the Debian/Ubuntu-supplied service units do not apply the mongo-recommended systemd service unit directives.)

Further reading

JdeBP
  • 3,979
4

I created a Systemd script that seems to work for Ubuntu 15.04+ and Mongo 3.0+:

[Unit]
Description=High-performance, schema-free document-oriented database
Documentation=man:mongod(1)
After=network.target

[Service]
Type=forking
User=mongodb
Group=mongodb
RuntimeDirectory=mongod
PIDFile=/var/run/mongod/mongod.pid
ExecStart=/usr/bin/mongod -f /etc/mongod.conf --pidfilepath /var/run/mongod/mongod.pid --fork
TimeoutStopSec=5
KillMode=mixed

[Install]
WantedBy=multi-user.target

https://gist.github.com/benileo/ada486d73f58dd93a0ee

Make sure you set your data directory in /etc/mongod.conf

A T
  • 2,578
benileo
  • 175
  • 6
1

Isn't this the best answer? From a duplicate question: https://askubuntu.com/a/694226/255468 by @sclausen


It's just the lack of a service file for systemd. No need to go back to upstart like Kartik did or use a different repository than described in https://docs.mongodb.org/manual/installation/.

Create a file /lib/systemd/system/mongodb.service with the following content:

[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target

[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongodb.conf

[Install]
WantedBy=multi-user.target
Sudhanshu
  • 446
1

https://jira.mongodb.org/browse/SERVER-17742

It seems that this possibly won't be fully fixed for >2.6.3 until Ubuntu 16.04, unless there is a strong outcry.

So the solution for me was to issue:

sudo apt-get install --reinstall mongodb
techraf
  • 3,316
0

use "mongodb" instead of "mongod"

i.e

sudo service mongodb start

sudo service mongodb stop
0

Many of these answers are related to Mongo 3.0, whereas the question asked specifically about 2.6.

I've had success installing 2.6 using the Debian repository from 10gen. This appears to work perfectly with Ubuntu 15.04.

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update
sudo apt-get install mongodb-org

Source: How to Install MongoDB 2.6 on Ubuntu 14.10, 14.04 and 12.04 LTS

0

While the question is for version 2.6. I was getting the exact same error Unit mongod.service failed to load in my Ubuntu 15.04 for version 3.0.6. Ultimately resolved using the same wheezy repository mentioned by Dielson Sales above.

And after the installation (following the steps detailed by @Dielson Sales) faced the above error. Here's how I finally resolved.

A) Change MongoDB's default data store files from /var/lib/mongodb to /data/db

  • First create the new /data/db directory sudo mkdir -p /data/db

  • Open mongod.conf file sudo gedit /etc/mongod.conf and change the “dbpath” line as below

  • Replace dbpath=/var/lib/mongodb TO dbpath=/data/db and save the file.

  • Then delete the old default /var/lib/mongodb

  • Now we must make all the directories/files owned by mongod user

B) So run sudo chown -R mongodb:mongodb /data/db

And now finally I can start mongo with sudo service mongod start

And chcek that the service is running with sudo systemctl status mongod - It should show a message similar to below

Loaded: loaded (/etc/init.d/mongod)

Active: active (running) since Thu 2015-09-03 04:57:49 IST; 7s ago

Have detailed my steps in my blog post

0

First, download mongodb:

curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz

extract download:

tar -zxvf mongodb-linux-x86_64-3.0.6.tgz

run the mongod (mongodb-linux-x86_64-3.0.6.tgz/bin/mongod) with -dbpath attribute:

sudo ./mongod --dbpath /path/of/the/directory

It can be an empty directory any of your choice

and finally, run mongo (mongodb-linux-x86_64-3.0.6.tgz/bin/mongo)

./mongo

worked on my ubuntu 15 :)

sorry for my bad english , I live in Brazil

0

After hours from searching, The solution was to upgrade my ubuntu from 15.04 to 16.04 using this command:

Step 1

sudo do-release-upgrade -d 

It will take few minutes so dont panic, than you have to remove mongodb :

Step 2

sudo apt-get purge mongodb-org 
sudo apt-get autoremove`  
rm /etc/apt/sources.list.d/mongodb-org-3.0.list`  

And now, install mongodb but using this source :

echo 'deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.0 main' | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list

Step 3

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10  
echo ‘deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.0 main’ | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
sudo apt-get update
sudo apt-get install mongodb-org
sudo service mongod status

And that's it.

Note : If you get an error like ' E: the type 'deb' in the first line . . . in the file mongodb-org-3.0.list

all you have to do is to get in this file using gedit and delete the ‘ in the begin and at the end of the sentence.

muru
  • 207,228
0

Ubuntu 15.04+ uses systemd instead of upstart. Start with MongoDB's official install guide. Then use their official mongod.service:

[Unit]
Description=High-performance, schema-free document-oriented database

[Service]
User=mongod
Group=mongod
Environment="OPTIONS=--quiet -f /etc/mongod.conf"
ExecStart=/usr/local/bin/mongod $OPTIONS run
PIDFile=/var/run/mongodb/mongod.pid

[Install]
WantedBy=multi-user.target

Download, patch, install service and setup dir+permissions

$ curl -OL https://raw.githubusercontent.com/mongodb/mongo/1663f45b4e33e058a0203a81f50574a870882c34/rpm/mongod.service
$ sed -i 's/\/usr\/local/\/usr/g' mongod.service
$ sed -i '/Desc/a After=network.target' mongod.service
$ sudo sed -i '0,/\/var\/lib\/mongodb/s//\/data\/db/' /etc/mongod.conf
$ sudo cp mongod.service /lib/systemd/system/mongo.service
$ sudo mkdir -p /data/db
$ sudo chown -R mongodb:mongodb /data
$ sudo systemctl daemon-reload
$ sudo systemctl enable mongod

Start service

$ sudo systemctl start mongod

Check service status

$ sudo systemctl status mongod
A T
  • 2,578
0

You made a typo in your command.

Try using this instead: sudo service mongodb start

Thomas Ward
  • 78,878