首页 > 解决方案 > 我搞砸了我的 MongoDB 安装,我需要帮助删除它以重新安装它

问题描述

只是为了透明,我不知道怎么做,但我确定我把自己挖到了一个洞里。假设我是驴脑。这是 Ubuntu 的全新安装 - 我在这方面的宝贵数据为零,因此如果我需要删除任何内容,我关心的不会丢失任何东西。

我尝试在 Ubuntu 20.04 上安装 MongoDB。后来我意识到有一种不同的方法可以做到这一点,但我按照学校的指示使用自制软件安装它。这对我来说真的不太好,所以我找到了一个与学校不同的指南,涵盖了 Ubuntu 安装。我通过执行以下操作来遵循

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

然后指南开始和停止服务并检查它, sudo service mongodb status但返回Unit mongodb.service could not be found

我认为我的安装搞砸了,我把它搞砸了,所以我只需要找到一个卸载和重新安装的指南。所以我开始寻找卸载指南,我发现这个Failed to start mongod.service: Unit mongod.service not found所以我以 58 票尝试了该卸载指南。

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

这基本上告诉我那些东西不存在。所以我认为我最好继续安装,因为我什至找不到我想要删除的东西。所以我继续进行安装,前几步运行良好,但我被困在这里 -

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

所以我有点卡住了,我真的不知道在哪里看这一点。前几天晚上我让它工作了,但我相信它归结为配置文件的一些所有权问题?而且我不记得那个指南在我横冲直撞时去了哪里。但是我能够从学校得到我的项目,运行nodemon start它,它表明我已连接到 localhost:27017 和一切。我重新启动了我的电脑,只是想看看第二天我是否会遇到任何奇怪的事情,果然它不会再工作了。我试图找到我之前参考过的指南,但我丢失了它......

标签: mongodbubuntu

解决方案


我发现我的问题是我在 zsh 而不是 Bash 中运行命令。所以我做了exec bash,然后从这个堆栈溢出中进行以下操作无法在 ubuntu 18.04 LTS 上正确安装 mongodb

需要先卸载mongodb,可以使用:

sudo apt-get purge mongodb-org*

在此之后,通过以下命令安装 mongodb:

sudo apt-get install mongodb

然后更新:

sudo apt-get update

您已完成 mongodb 的安装。您可以使用以下命令进行检查:

mongo --version

一旦我完成了,一切看起来都很好。跑回zsh,然后通过运行nodemonexec zsh再次测试我的应用程序,一切都很好。


推荐阅读