尝试安装 mongodb 时出现 dpkg 错误

尝试安装 mongodb 时出现 dpkg 错误

对这些 dpkg 错误不太熟悉,我猜可能是我破坏了 apt 源?

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-filesystem1.71.0 libboost-iostreams1.71.0
  libboost-program-options1.71.0 libgoogle-perftools4 libpcrecpp0v5
  libsnappy1v5 libtcmalloc-minimal4 libyaml-cpp0.6 mongo-tools
  mongodb-server-core
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  mongodb-database-tools mongodb-org-mongos mongodb-org-server
The following NEW packages will be installed:
  mongodb-database-tools mongodb-org-mongos mongodb-org-server
0 upgraded, 3 newly installed, 0 to remove and 10 not upgraded.
4 not fully installed or removed.
Need to get 0 B/90.6 MB of archives.
After this operation, 147 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 131946 files and directories currently installed.)
Preparing to unpack .../mongodb-org-server_4.4.2_amd64.deb ...
Unpacking mongodb-org-server (4.4.2) ...
dpkg: error processing archive /var/cache/apt/archives/mongodb-org-server_4.4.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
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Preparing to unpack .../mongodb-org-mongos_4.4.2_amd64.deb ...
Unpacking mongodb-org-mongos (4.4.2) ...
dpkg: error processing archive /var/cache/apt/archives/mongodb-org-mongos_4.4.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
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Preparing to unpack .../mongodb-database-tools_100.2.1_amd64.deb ...
Unpacking mongodb-database-tools (100.2.1) ...
dpkg: error processing archive /var/cache/apt/archives/mongodb-database-tools_100.2.1_amd64.deb (--unpack):
 trying to overwrite '/usr/bin/bsondump', which is also in package mongo-tools 3.6.3-0ubuntu1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/mongodb-org-server_4.4.2_amd64.deb
 /var/cache/apt/archives/mongodb-org-mongos_4.4.2_amd64.deb
 /var/cache/apt/archives/mongodb-database-tools_100.2.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
root@configsfun:~# sudo apt -f 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-filesystem1.71.0 libboost-iostreams1.71.0
  libboost-program-options1.71.0 libgoogle-perftools4 libpcrecpp0v5
  libsnappy1v5 libtcmalloc-minimal4 libyaml-cpp0.6 mongo-tools
  mongodb-server-core
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  mongodb-database-tools mongodb-org-mongos mongodb-org-server
The following NEW packages will be installed:
  mongodb-database-tools mongodb-org-mongos mongodb-org-server
0 upgraded, 3 newly installed, 0 to remove and 10 not upgraded.
4 not fully installed or removed.
Need to get 0 B/90.6 MB of archives.
After this operation, 147 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 131946 files and directories currently installed.)
Preparing to unpack .../mongodb-org-server_4.4.2_amd64.deb ...
Unpacking mongodb-org-server (4.4.2) ...
dpkg: error processing archive /var/cache/apt/archives/mongodb-org-server_4.4.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
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Preparing to unpack .../mongodb-org-mongos_4.4.2_amd64.deb ...
Unpacking mongodb-org-mongos (4.4.2) ...
dpkg: error processing archive /var/cache/apt/archives/mongodb-org-mongos_4.4.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
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Preparing to unpack .../mongodb-database-tools_100.2.1_amd64.deb ...
Unpacking mongodb-database-tools (100.2.1) ...
dpkg: error processing archive /var/cache/apt/archives/mongodb-database-tools_100.2.1_amd64.deb (--unpack):
 trying to overwrite '/usr/bin/bsondump', which is also in package mongo-tools 3.6.3-0ubuntu1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/mongodb-org-server_4.4.2_amd64.deb
 /var/cache/apt/archives/mongodb-org-mongos_4.4.2_amd64.deb
 /var/cache/apt/archives/mongodb-database-tools_100.2.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

答案1

sudo apt purge mongodb-*清除所有旧的 mongodb 包

dpkg -l | grep mongo检查是否还有与 mongo 相关的东西需要卸载:

user@ubuntu:~$ dpkg -l | grep mongo
ii  mongo-tools                                3.6.3-0ubuntu1                        amd64        collection of tools for administering MongoDB servers

sudo apt purge mongo-tools然后尝试再次安装较新的 mongodb。

答案2

发生这种情况是因为您的计算机中已经安装了 Ubuntu 自带的 mongodb。您可以找到详细的解决方案这里。我建议你看一下。为了方便起见,我将在下面列出解决方案。

在终端或 shell 中运行以下命令,以完全删除 Ubuntu mongodb 包,然后再重试安装过程:

sudo apt remove mongodb
sudo apt purge mongodb
sudo apt autoremove

答案3

我花了很多时间寻找这个答案——这是 2021 年唯一有效的答案(与正确清除和重新安装有关):

https://stackoverflow.com/a/48871898/6541639

相关内容