Ubuntu – MongoDB installation failed on Ubuntu 16.04

16.04aptmongodb

I followed instructions given on the official MongoDB website (https://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/) and I get this error when trying to install MongoDB. How to fix this issue and what's going wrong? Remember I'm using latest Ubuntu version 16.04

sudo apt-get install -y mongodb-org

Reading package lists... Done

Building dependency tree

Reading state information... Done

You might want to run 'apt-get -f install' to correct these:

The following packages have unmet dependencies:

mongodb-org : 

Depends: mongodb-org-shell but it is not going to be installed

Depends: mongodb-org-server but it is not going to be installed

Depends: mongodb-org-mongos but it is not going to be installed

Depends: mongodb-org-tools but it is not going to be installed

virtualbox-5.0 : Depends: libqt4-opengl (>= 4:4.7.2) but it is not going to be installed

Depends: libsdl1.2debian (>= 1.2.11) but it is not going to be installed

Recommends: libsdl-ttf2.0-0 but it is not going to be installed

E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

Edit: Title. MongDB -> MongoDB.

Best Answer

Install mongodb in Ubuntu 12.04, 14.04 ,16.04

  1. Import the public key used by the package management system

    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
    
  2. Create a list file for MongoDB.

    In Ubuntu 12.04 (deprecated):

    echo "deb http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
    

    In Ubuntu 14.04:

    echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
    

    In Ubuntu 16.04:

    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
    
  3. Reload local package database.

    sudo apt-get update
    

    It will throw a warning

    W: http://repo.mongodb.org/apt/ubuntu/dists/trusty/mongodb-org/3.0/Release.gpg: Signature by key 492EAFE8CD016A07919F1D2B9ECBEC467F0CEB10 uses weak digest algorithm (SHA1)
    

    Just Ignore It.

  4. Install the MongoDB packages.

    sudo apt-get install -y mongodb-org
    

After installation you can start MongoDB using

sudo service mongod start

To stop MongoDB use

sudo service mongod stop

To restart MongoDB use

sudo service mongod restart

If that didn't work, check here to see if any of the steps have been updated: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

Related Question