How do I install MongoDB 3.0 in Vivid?

The official vivid package for mongodb is 2.x, and the packages that MongoDB provide themselves on http://repo.mongodb.org/apt/ubuntu/dists/trusty/ are only available for LTS releases.

An alternative is that I could switch back to 14.04 LTS, but I would need to install openjdk-8-jdk, which is only available for vivid.


Solution 1:

It's possible, that MongoDB doesn't start if you use the Trusty packages:

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

In this case, install the Debian Wheezy packages as described at the end.

Install the Trusty DEB packages

Download the DEB files

cd
wget http://repo.mongodb.org/apt/ubuntu/dists/trusty/mongodb-org/3.0/multiverse/binary-amd64/mongodb-org-mongos_3.0.3_amd64.deb
wget http://repo.mongodb.org/apt/ubuntu/dists/trusty/mongodb-org/3.0/multiverse/binary-amd64/mongodb-org-server_3.0.3_amd64.deb
wget http://repo.mongodb.org/apt/ubuntu/dists/trusty/mongodb-org/3.0/multiverse/binary-amd64/mongodb-org-shell_3.0.3_amd64.deb
wget http://repo.mongodb.org/apt/ubuntu/dists/trusty/mongodb-org/3.0/multiverse/binary-amd64/mongodb-org-tools_3.0.3_amd64.deb
wget http://repo.mongodb.org/apt/ubuntu/dists/trusty/mongodb-org/3.0/multiverse/binary-amd64/mongodb-org_3.0.3_amd64.deb

And install with (in this order)

sudo dpkg -i mongodb-org-server_3.0.3_amd64.deb
sudo dpkg -i mongodb-org-tools_3.0.3_amd64.deb
sudo dpkg -i mongodb-org-shell_3.0.3_amd64.deb
sudo dpkg -i mongodb-org-mongos_3.0.3_amd64.deb
sudo dpkg -i mongodb-org_3.0.3_amd64.deb

And taken from the comments, thank you @Pilot6:

They may have dependencies to each other. That's why installation packages one by one may give errors. I suggest sudo dpkg -i mongodb*.deb


Use the Trusty PPA

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org

Use the Debian Wheezy packages

It's possible, that MongoDB doesn't start if you use the Trusty packages:

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

In this case, install the Debian Wheezy packages as described below

sudo apt-get remove mongodb-org
sudo apt-get autoremove
sudo rm /etc/apt/sources.list.d/mongodb-org-3.0.list
sudo 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 -y mongodb-org

Solution 2:

Successfully installed with mongo version 3.0.6 in my Ubuntu 15.04 using debian wheezy repository - see below steps

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 -y mongodb-org

However, after all the steps above and mongodb installed in my machine, now when I tried to start the mongodb service with sudo service mongod start it would fail. Throwing the following error message

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

So here is how I resolved and startup mongodb normally

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

  • sudo mkdir -p /data/db

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

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

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

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

  • 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.

Solution 3:

As I have said before: The Debian/Ubuntu packages have been patched with systemd service units, to fill the hole left by the stuff that is published directly from mongodb.org. But 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. There's also a service unit published by mongodb.org, indeed. It is simply the case that the mongodb.org people have mistakenly conflated the use of RPM with the use of systemd in the distribution-specific stuff.

Note that, ironically, the mongodb.org-supplied service units do not apply the systemd service unit directives that mongodb.org itself recommends. Neither do the Debian/Ubuntu-supplied ones. But, again: A hand-written service unit with these directives isn't hard to write; or indeed to modify to add things like numactl. ☺

Further reading

  • https://unix.stackexchange.com/a/187540/5132
  • https://askubuntu.com/a/617869/43344