Home > front end >  I screwed up my installation of MongoDB and I need help removing it to reinstall it
I screwed up my installation of MongoDB and I need help removing it to reinstall it

Time:11-13

Just to be transparent, I don't know how but I'm sure I dug myself into a hole. Assume I'm donkey-brain. This is a brand new install of Ubuntu - I have zero precious data on this so there will be nothing lost I care about if I need to remove literally anything.

I tried to install MongoDB on Ubuntu 20.04. I realized there was a different way to do it later, but I followed my schools instructions to install it using homebrew. That didn't really work out too well for me so I found a different guide from the school that covered the Ubuntu installation. I followed that by doing the following

    sudo apt update
    sudo apt-get install mongodb
    mongod --version \\which works still, returns im on version 3.6.8

Then the guide goes over starting and stopping the service with and checking it sudo service mongodb status but that returns Unit mongodb.service could not be found

I figured my installation is screwed, I messed it up somewhere or something so I'll just find a guide to uninstall and re-install. So I started looking for a guide to uninstall and I found this Failed to start mongod.service: Unit mongod.service not found so I tried that uninstall guide with 58 votes.

sudo service mongod stop
sudo apt-get purge mongodb-org*
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb

Which basically tells me those things aren't there. So I thought I would be good to continue with the install since I couldn't even find the things I wanted to remove. So I proceeded with the install side which went fine for the first few steps but I got stuck here -

➜  lib sudo apt-get install -y mongodb-org
Reading package lists... Done
Building dependency tree       
Reading state information... Done
mongodb-org is already the newest version (5.0.3).
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 mongodb-org-database : Depends: mongodb-org-server but it is not going to be installed
                        Depends: mongodb-org-mongos but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
➜  lib sudo apt --fix-broken install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
  libboost-program-options1.71.0 libgoogle-perftools4 libpcrecpp0v5
  libsnappy1v5 libtcmalloc-minimal4 libyaml-cpp0.6 mongodb-server-core
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  mongodb-org-mongos mongodb-org-server
The following NEW packages will be installed:
  mongodb-org-mongos mongodb-org-server
0 upgraded, 2 newly installed, 0 to remove and 4 not upgraded.
12 not fully installed or removed.
Need to get 0 B/44.6 MB of archives.
After this operation, 183 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 224051 files and directories currently installed.)
Preparing to unpack .../mongodb-org-server_5.0.3_amd64.deb ...
Unpacking mongodb-org-server (5.0.3) ...
dpkg: error processing archive /var/cache/apt/archives/mongodb-org-server_5.0.3_
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.3
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Preparing to unpack .../mongodb-org-mongos_5.0.3_amd64.deb ...
Unpacking mongodb-org-mongos (5.0.3) ...
dpkg: error processing archive /var/cache/apt/archives/mongodb-org-mongos_5.0.3_
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.3
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/mongodb-org-server_5.0.3_amd64.deb
 /var/cache/apt/archives/mongodb-org-mongos_5.0.3_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
➜  lib sudo service mongodb status
[sudo] password for brainzilla: 
Unit mongodb.service could not be found.

So I'm kind of stuck, I don't really know where to look at this point tbh. I had it working at one point the other night, but I believe it came down to some ownership issue of the config file?? And I can't remember where that guide went on my rampage went. But I was able get my project from school, run nodemon start and it showed I was connected to localhost:27017 and everything. I rebooted my PC just to see if I would run into anything weird the next day and sure enough it wouldn't work again. I tried to find the guide I had referenced before but I lost it...

CodePudding user response:

I found that my problem was that I was running commands in zsh and not in Bash. So I did exec bash and then the following from this stack overflow Unable to install mongodb properly on ubuntu 18.04 LTS

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

Once I was done and everything looked good. Ran exec zsh to get back to zsh, then tested my app again by running nodemon and everything is good.

  • Related