Score:0

Trouble installing MongoDB on Linux Ubuntu 20.04

cn flag

Others have asked this question, but I have found no answer that works for me. I am trying to install MongoDB on Ubuntu 20.04. I have been following the guide at https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/, but run into trouble during installation. An error occurs during install (first error below), then I verify the install worked with --version command, it seems installed, I try to run, and get the subsequent failure (mongod.service not found).

Errors were encountered while processing:
 /tmp/apt-dpkg-install-kD4T9j/0-mongodb-database-tools_100.5.0_amd64.deb
 /tmp/apt-dpkg-install-kD4T9j/3-mongodb-org-server_5.0.2_amd64.deb
 /tmp/apt-dpkg-install-kD4T9j/4-mongodb-org-mongos_5.0.2_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
jared@Pandora:~$ mongo --version
MongoDB shell version v5.0.2
Build Info: {
    "version": "5.0.2",
    "gitVersion": "6d9ec525e78465dcecadcff99cce953d380fedc8",
    "openSSLVersion": "OpenSSL 1.1.1f  31 Mar 2020",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "ubuntu2004",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}
jared@Pandora:~$ sudo systemctl start mongod
Failed to start mongod.service: Unit mongod.service not found.
jared@Pandora:~$ sudo systemctl daemon-reload
jared@Pandora:~$ sudo systemctl start mongod
Failed to start mongod.service: Unit mongod.service not found.

Then I tried again double checking to remove previous files as per Cool Kev's advice below. Here is the complete new install and error printout:

jared@Pandora:~$ sudo apt install mongodb-org
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  mongodb-database-tools mongodb-mongosh mongodb-org-database
  mongodb-org-database-tools-extra mongodb-org-mongos mongodb-org-server
  mongodb-org-shell mongodb-org-tools
The following NEW packages will be installed:
  mongodb-database-tools mongodb-mongosh mongodb-org mongodb-org-database
  mongodb-org-database-tools-extra mongodb-org-mongos mongodb-org-server
  mongodb-org-shell mongodb-org-tools
0 upgraded, 9 newly installed, 0 to remove and 23 not upgraded.
Need to get 0 B/147 MB of archives.
After this operation, 449 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
(Reading database ... 197683 files and directories currently installed.)
Preparing to unpack .../0-mongodb-database-tools_100.5.0_amd64.deb ...
Unpacking mongodb-database-tools (100.5.0) ...
Selecting previously unselected package mongodb-mongosh.
Preparing to unpack .../1-mongodb-mongosh_1.0.6_amd64.deb ...
Unpacking mongodb-mongosh (1.0.6) ...
Selecting previously unselected package mongodb-org-shell.
Preparing to unpack .../2-mongodb-org-shell_5.0.2_amd64.deb ...
Unpacking mongodb-org-shell (5.0.2) ...
Preparing to unpack .../3-mongodb-org-server_5.0.2_amd64.deb ...
Unpacking mongodb-org-server (5.0.2) ...
dpkg: error processing archive /tmp/apt-dpkg-install-h1NnWS/3-mongodb-org-server
_5.0.2_amd64.deb (--unpack):
 trying to overwrite '/usr/bin/mongod', which is also in package mongodb-server-
core 1:3.6.9+really3.6.8+90~g8e540c0b6d-0ubuntu5.2
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Preparing to unpack .../4-mongodb-org-mongos_5.0.2_amd64.deb ...
Unpacking mongodb-org-mongos (5.0.2) ...
dpkg: error processing archive /tmp/apt-dpkg-install-h1NnWS/4-mongodb-org-mongos
_5.0.2_amd64.deb (--unpack):
 trying to overwrite '/usr/bin/mongos', which is also in package mongodb-server-
core 1:3.6.9+really3.6.8+90~g8e540c0b6d-0ubuntu5.2
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Selecting previously unselected package mongodb-org-database-tools-extra.
Preparing to unpack .../5-mongodb-org-database-tools-extra_5.0.2_amd64.deb ...
Unpacking mongodb-org-database-tools-extra (5.0.2) ...
Selecting previously unselected package mongodb-org-database.
Preparing to unpack .../6-mongodb-org-database_5.0.2_amd64.deb ...
Unpacking mongodb-org-database (5.0.2) ...
Selecting previously unselected package mongodb-org-tools.
Preparing to unpack .../7-mongodb-org-tools_5.0.2_amd64.deb ...
Unpacking mongodb-org-tools (5.0.2) ...
Selecting previously unselected package mongodb-org.
Preparing to unpack .../8-mongodb-org_5.0.2_amd64.deb ...
Unpacking mongodb-org (5.0.2) ...
Errors were encountered while processing:
 /tmp/apt-dpkg-install-h1NnWS/3-mongodb-org-server_5.0.2_amd64.deb
 /tmp/apt-dpkg-install-h1NnWS/4-mongodb-org-mongos_5.0.2_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
jared@Pandora:~$ mongo --version
MongoDB shell version v5.0.2
Build Info: {
    "version": "5.0.2",
    "gitVersion": "6d9ec525e78465dcecadcff99cce953d380fedc8",
    "openSSLVersion": "OpenSSL 1.1.1f  31 Mar 2020",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "ubuntu2004",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}
jared@Pandora:~$ mongod
2021-09-15T21:55:30.223-0400 I CONTROL  [initandlisten] MongoDB starting : pid=25491 port=27017 dbpath=/data/db 64-bit host=Pandora
2021-09-15T21:55:30.223-0400 I CONTROL  [initandlisten] db version v3.6.8
2021-09-15T21:55:30.223-0400 I CONTROL  [initandlisten] git version: 8e540c0b6db93ce994cc548f000900bdc740f80a
2021-09-15T21:55:30.223-0400 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.1.1f  31 Mar 2020
2021-09-15T21:55:30.223-0400 I CONTROL  [initandlisten] allocator: tcmalloc
2021-09-15T21:55:30.223-0400 I CONTROL  [initandlisten] modules: none
2021-09-15T21:55:30.223-0400 I CONTROL  [initandlisten] build environment:
2021-09-15T21:55:30.223-0400 I CONTROL  [initandlisten]     distarch: x86_64
2021-09-15T21:55:30.223-0400 I CONTROL  [initandlisten]     target_arch: x86_64
2021-09-15T21:55:30.223-0400 I CONTROL  [initandlisten] options: {}
2021-09-15T21:55:30.223-0400 I STORAGE  [initandlisten] exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating
2021-09-15T21:55:30.223-0400 I CONTROL  [initandlisten] now exiting
2021-09-15T21:55:30.223-0400 I CONTROL  [initandlisten] shutting down with code:100
jared@Pandora:~$ mongo
MongoDB shell version v5.0.2
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:372:17
@(connect):2:6
exception: connect failed
exiting with code 1
jared@Pandora:~$ 
user535733 avatar
cn flag
Since the install failed, service-not-found is a reasonable and expected result. Edit your question to show the complete install output -- the summary that you included is not detailed enough to help you.
Jared Dubin avatar
cn flag
Thanks for pointing that out, I see what you mean. I included a complete install output on my latest attempt, made after what I hope was a complete purge following Kev Cool's instructions. The complete output is pasted on the original post below the first attempt. Looks like something about a broken pipe? Thanks!
user535733 avatar
cn flag
Read the two lines *above* the `broken pipe`. Package A and Package B are both trying to provide File X. Packages A and B *conflict*. If you want to install A, you must remove B first. Everything you need is in that output!
Terrance avatar
id flag
https://askubuntu.com/a/842599/231142 might help as I just installed MongoDB 5.0.2 as a test in 20.04.
Jared Dubin avatar
cn flag
I got it! for some reason this command seemed to thoroughly remove all the old mongo files: sudo apt-get purge mongodb-*
Score:0
cn flag

Solved! Seems like:

sudo apt-get purge mongodb-*

was able to actually rid my system of all old mongo files, allowing me a clean install. Thanks for all who helped!

Score:0
ma flag

Just to confirm, you didn't already have the MongoDB package provided by Ubuntu installed before installing the package from the mongodb.org repository that you added during installation correctly? It might go without saying but there are pkg conflicts. If you're unsure if there were preexisting versions, you could always:

sudo apt remove mongodb-org*
sudo apt remove mongodb
sudo apt autoremove

Assuming no snags there, reattempt install of the mongo.org version

sudo apt install mongodb-org
Jared Dubin avatar
cn flag
Yes, I did try to remove before and I did the same process again, this time using the remove commands you recommended. I pasted the new install and error results in the original message, below the first set of errors. Thanks for the help!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.