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 Answers 13

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)

9
  • 1
    I tried that and got service not found when trying to start mongod
    – Zippo
    May 9, 2015 at 7:51
  • 2
    Are you sure you autoremoved the dependencies? I got that too, but then I realized I hadn't removed all mongodb related packages. After removing all of them and installed from wheezy repository, it's working fine with systemd. May 10, 2015 at 0:27
  • 1
    saved me a lot of headache May 12, 2015 at 23:10
  • 1
    Thank you. Purge followed by autoremove (almost forgot it) did the trick. May 31, 2015 at 14:32
  • In my case on 14.04 but likely on 15.04 tailing /var/log/syslog, verifying the failed attempt then editing /etc/init/mongodb.confcan also help if you are using a non-standard data directory, log directory, or user instance. Jul 10, 2015 at 17:14
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.

6
  • 2
    This is the best way to solve this problem by now. If anyone knows other ways, please share here. May 4, 2015 at 18:43
  • In my case installing upstart-sysv and restarting just crashes. May 5, 2015 at 9:30
  • @DidacMontero Look at wiki.ubuntu.com/SystemdForUpstartUsers for other options
    – Zippo
    May 9, 2015 at 7:49
  • Works for me on Ubuntu 15.04, thanks for the work-around!
    – Lil' Bits
    May 22, 2015 at 13:50
  • this worked perfectly for me.
    – user459171
    Oct 10, 2015 at 2:26
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

2
  • However this approach doesn't solve the problem for those who want MongoDB >= 3.0 May 12, 2015 at 17:41
  • Yes it does. You clearly didn't read either the second paragraph or the further reading.
    – JdeBP
    May 13, 2015 at 6:21
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

4
  • 1
    This is the best solution.
    – J. Bruni
    Nov 22, 2015 at 18:58
  • link no longer works
    – Hotbelgo
    Jan 17, 2016 at 10:44
  • Fixed the link.
    – benileo
    Jan 18, 2016 at 15:26
  • For sure, it's should be marked as the best solution. Jul 20, 2016 at 12:02
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
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
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.

2
  • This part "The solution was to upgrade my ubuntu from 15.04 to 16.04..." doesn't make sense at the moment, because 16.04 is not released yet.
    – user37165
    Jan 3, 2016 at 6:50
  • 1
    @clearkimura Yes it is. Well, in alpha. And whatever, the second daily build of Ubuntu 16.04 is installed on my computer, and i've seen no problems.
    – Star OS
    Jan 3, 2016 at 9:04
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
0

You made a typo in your command.

Try using this instead: sudo service mongodb start

0

use "mongodb" instead of "mongod"

i.e

sudo service mongodb start

sudo service mongodb stop

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .