我遵循的是官方文档中写的完全相同的程序,尽管我很清楚我的 Ubuntu 版本不是 LTS。
所有步骤都顺利,直到安装 MongoDB 命令的最后一步。您可以在此处看到错误。
vks@247:~$ sudo apt-get install -y mongodb-org
Reading package lists... Done
Building dependency tree
Reading state information... Done
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).
我也尝试了命令:apt --fix-broken install,但是它不起作用并显示以下内容:
vks@247:~$ sudo apt --fix-broken install
[sudo] password for vks:
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.67.0 libgoogle-perftools4 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-org-mongos mongodb-org-server mongodb-org-tools
The following NEW packages will be installed:
mongodb-org-mongos mongodb-org-server mongodb-org-tools
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
2 not fully installed or removed.
Need to get 0 B/85.7 MB of archives.
After this operation, 248 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
(Reading database ... 217305 files and directories currently installed.)
Preparing to unpack .../mongodb-org-server_4.2.5_amd64.deb ...
Unpacking mongodb-org-server (4.2.5) ...
dpkg: error processing archive /var/cache/apt/archives/mongodb-org-server_4.2.5_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-0ubuntu2
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Preparing to unpack .../mongodb-org-mongos_4.2.5_amd64.deb ...
Unpacking mongodb-org-mongos (4.2.5) ...
dpkg: error processing archive /var/cache/apt/archives/mongodb-org-mongos_4.2.5_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-0ubuntu2
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Preparing to unpack .../mongodb-org-tools_4.2.5_amd64.deb ...
Unpacking mongodb-org-tools (4.2.5) ...
dpkg: error processing archive /var/cache/apt/archives/mongodb-org-tools_4.2.5_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.2.5_amd64.deb
/var/cache/apt/archives/mongodb-org-mongos_4.2.5_amd64.deb
/var/cache/apt/archives/mongodb-org-tools_4.2.5_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
在此之后,我也尝试安装指定的版本(尽管是相同的版本)。
vks@247:~$ sudo apt-get install -y mongodb-org=4.2.5 mongodb-org-server=4.2.5 mongodb-org-shell=4.2.5 mongodb-org-mongos=4.2.5 mongodb-org-tools=4.2.5
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libboost-program-options1.67.0 libgoogle-perftools4 libtcmalloc-minimal4
libyaml-cpp0.6 mongo-tools mongodb-server-core
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
mongodb-org-mongos mongodb-org-server mongodb-org-tools
The following packages will be upgraded:
mongodb-org mongodb-org-shell
2 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
Need to get 97.7 MB of archives.
After this operation, 255 MB of additional disk space will be used.
Get:1 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2/multiverse amd64 mongodb-org-shell amd64 4.2.5 [12.0 MB]
Get:2 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2/multiverse amd64 mongodb-org-server amd64 4.2.5 [18.5 MB]
Get:3 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2/multiverse amd64 mongodb-org-mongos amd64 4.2.5 [10.2 MB]
Get:4 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2/multiverse amd64 mongodb-org-tools amd64 4.2.5 [57.0 MB]
Get:5 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2/multiverse amd64 mongodb-org amd64 4.2.5 [3,532 B]
Fetched 97.7 MB in 20s (4,836 kB/s)
(Reading database ... 217305 files and directories currently installed.)
Preparing to unpack .../mongodb-org-shell_4.2.5_amd64.deb ...
Unpacking mongodb-org-shell (4.2.5) over (4.0.17) ...
Preparing to unpack .../mongodb-org-server_4.2.5_amd64.deb ...
Unpacking mongodb-org-server (4.2.5) ...
dpkg: error processing archive /var/cache/apt/archives/mongodb-org-server_4.2.5_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-0ubuntu2
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Preparing to unpack .../mongodb-org-mongos_4.2.5_amd64.deb ...
Unpacking mongodb-org-mongos (4.2.5) ...
dpkg: error processing archive /var/cache/apt/archives/mongodb-org-mongos_4.2.5_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-0ubuntu2
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Preparing to unpack .../mongodb-org-tools_4.2.5_amd64.deb ...
Unpacking mongodb-org-tools (4.2.5) ...
dpkg: error processing archive /var/cache/apt/archives/mongodb-org-tools_4.2.5_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)
Preparing to unpack .../mongodb-org_4.2.5_amd64.deb ...
Unpacking mongodb-org (4.2.5) over (4.0.17) ...
Errors were encountered while processing:
/var/cache/apt/archives/mongodb-org-server_4.2.5_amd64.deb
/var/cache/apt/archives/mongodb-org-mongos_4.2.5_amd64.deb
/var/cache/apt/archives/mongodb-org-tools_4.2.5_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
问题依然如故。
我也尝试过从各个网站解决该问题,但都无法解决。如能得到任何帮助我将不胜感激。
答案1
我遇到了同样的问题,我在安装手册上花了一点功夫就找到了原因和解决方法。
trying to overwrite '/usr/bin/mongod', which is also in package mongodb-server-core 1:3.6.9+really3.6.8+90~g8e540c0b6d-0ubuntu2
此错误表明系统在安装官方 MongoDB Inc. mongodb-org 包之前已经安装了 Ubuntu mongodb 包。要确认主机是否安装了 Ubuntu mongodb 包,请在终端或 shell 中运行以下命令:
因此,您需要删除现有的 mongodb 包,然后进行全新安装。确保在删除现有安装之前进行必要的备份。
1. 删除部分安装的 mongodb-org 包
sudo apt-get purge mongodb-org*
2.删除现有的mongodb包
sudo apt remove mongodb
sudo apt purge mongodb
sudo apt autoremove
3.重新安装mongodb-org
sudo apt-get install -y mongodb-org
干杯!!