Question

Unable to install mongodb properly on ubuntu 18.04 LTS

I am trying to install mongodb on my Ubuntu 18.04 LTS, but it has the following error saying

You might want to run 'apt --fix-broken install' to correct these. The following packages have unmet dependencies: mongodb-org : 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 E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution). umar@umar-Lenovo-ideapad-320-15ISK:~/Desktop/portfolio/async-demo$ sudo apt-get install -y mongodb

I beleieve the reason behind this is already mentioned on their website, clearly saying

PLATFORM SUPPORT

MongoDB only provides packages for 64-bit LTS (long-term support) Ubuntu releases; for example, 14.04 LTS (trusty) and 16.04 LTS (xenial). See Supported Platforms for more information.

These packages may work with other Ubuntu releases; however, they are not supported.

So how can I install mongodb on my latest Ubuntu 18.04 LTS? For sake of clarity, I am listing the things I did to correct the errors: I followed their official website to install mongodb

1. sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
2. echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
3. sudo apt-get update
4. sudo apt-get install -y mongodb-org

Now here I got errors saying: You might want to run 'apt --fix-broken install' to correct these. The following packages have unmet dependencies:

I tried,

apt --fix-broken install

It did not work, somewhere I got clue to run

sudo apt -f install

It also returned error.

Errors were encountered while processing: /var/cache/apt/archives/mongodb-org-server_4.0.0_amd64.deb /var/cache/apt/archives/mongodb-org-mongos_4.0.0_amd64.deb /var/cache/apt/archives/mongodb-org-tools_4.0.0_amd64.deb E: Sub-process /usr/bin/dpkg returned an error code (1)

I believe the main problem is compatability with version. So basically I have Ubuntu 18.04, how I install mongodb on this version, so that I can work without any trouble.

 46  127959  46
1 Jan 1970

Solution

 150

You need to first uninstall the mongodb, you can use:

sudo apt-get purge mongodb-org*

After this, install mongodb through the following commands:

sudo apt-get install mongodb

And then update:

sudo apt-get update

You are done with the installation of mongodb. You can check it by using the below command:

mongo --version
2018-07-19

Solution

 27

EDIT: It's been a number of years, and unfortunately the top answer still points users away from the latest stable version of MongoDB. In fact the last available package for mongodb is 3.6.3.

I don't work at the company anymore, but I will point to:

https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/

That's the best way to install the latest stable version MongoDB. It includes instructions for adding the necessary repositories and keys to allow running apt install mongodb-org. There is a platform support matrix that will help with identifying which versions of MongoDB you can install on any given Linux OS version.

just want to chime in here. I'm the Senior Technical Writer for MongoDB Server Docs. This post is one of a few that comes up with "install MongoDB on Ubuntu 18.04", and there are several comments here referencing the mongodb package for installation. The unofficial mongodb package provided by Ubuntu is not maintained by MongoDB. You should always use the official MongoDB mongodb-org packages. Furthermore, from a bit of personal testing it looks like having mongodb installed will cause issues if you try to install mongodb-org, so its just added trouble

The few times I've run into this issue when testing locally, attempting to install one of the subpackages (i.e. mongodb-org-server) usually surfaced the actual error (i.e. missing libcurl3, which was removed in 18.04 as a default installed library). These issues may be more common when testing development builds ( at the time of writing, that's the 4.2 dev series).

To check which package you have installed on your local system, run the following:

sudo apt list --installed | grep mongo

This was my output after I installed mongodb, then attempted mongodb-org:

mongo-tools/bionic,now 3.6.3-0ubuntu1 amd64 [installed,auto-removable]
mongodb-org/bionic,now 4.0.5 amd64 [installed]
mongodb-org-shell/bionic,now 4.0.5 amd64 [installed,automatic]
mongodb-server-core/bionic,now 1:3.6.3-0ubuntu1 amd64 [installed,auto-removable]

So you can see, I've got a mix between the two packages (and a bunch of dkpg errors). I ended up using a mix of apt remove , apt autoremove, and apt purge to fix up the system.

2019-01-03