无法在 ubuntu 18.04 LTS 上正确安装 mongodb

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51417708/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 21:00:40  来源:igfitidea点击:

Unable to install mongodb properly on ubuntu 18.04 LTS

mongodbubuntu

提问by Umar

I am trying to install mongodb on my Ubuntu 18.04 LTS, but it has the following error saying

我正在尝试在我的 Ubuntu 18.04 LTS 上安装 mongodb,但它有以下错误提示

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). umar@umar-Lenovo-ideapad-320-15ISK:~/Desktop/portfolio/async-demo$ sudo apt-get install -y mongodb

您可能需要运行 'apt --fix-broken install' 来纠正这些问题。以下软件包具有未满足的依赖项: mongodb-org :依赖项: mongodb-org-server 但不会安装依赖项: mongodb-org-mongos 但​​不会安装依赖项: mongodb-org-tools 但它不会安装 E:未满足的依赖项。尝试不带软件包的“apt --fix-broken install”(或指定解决方案)。umar@umar-Lenovo-ideapad-320-15ISK:~/Desktop/portfolio/async-demo$ sudo apt-get install -y mongodb

I beleieve the reason behind this is already mentioned on their website, clearly saying

我相信这背后的原因已经在他们的网站上提到了,清楚地说

PLATFORM SUPPORT

MongoDB only provides packages for 64-bit LTS (long-term support) Ubuntu releases; for example, 14.04 LTS (trusty) and 16.04 LTS (xenial). See Supported Platforms for more information.

These packages may work with other Ubuntu releases; however, they are not supported.

平台支持

MongoDB 仅提供 64 位 LTS(长期支持)Ubuntu 版本的包;例如,14.04 LTS (trusty) 和 16.04 LTS (xenial)。有关更多信息,请参阅支持的平台。

这些软件包可能适用于其他 Ubuntu 版本;但是,它们不受支持。

So how can I install mongodb on my latest Ubuntu 18.04 LTS? For sake of clarity, I am listing the things I did to correct the errors: I followed their official website to install mongodb

那么如何在我最新的 Ubuntu 18.04 LTS 上安装 mongodb?为了清楚起见,我列出了我为纠正错误所做的事情:我按照他们的官方网站安装了mongodb

1. sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
2. echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
3. sudo apt-get update
4. sudo apt-get install -y mongodb-org

Now here I got errors saying: You might want to run 'apt --fix-broken install' to correct these. The following packages have unmet dependencies:

现在我收到错误提示:您可能需要运行 'apt --fix-broken install' 来纠正这些错误。以下软件包具有未满足的依赖项:

I tried,

我试过,

apt --fix-broken install

It did not work, somewhere I got clue to run

它没有用,在某个地方我得到了运行的线索

sudo apt -f install

It also returned error.

它也返回错误。

Errors were encountered while processing: /var/cache/apt/archives/mongodb-org-server_4.0.0_amd64.deb /var/cache/apt/archives/mongodb-org-mongos_4.0.0_amd64.deb /var/cache/apt/archives/mongodb-org-tools_4.0.0_amd64.deb E: Sub-process /usr/bin/dpkg returned an error code (1)

处理时遇到错误:/var/cache/apt/archives/mongodb-org-server_4.0.0_amd64.deb /var/cache/apt/archives/mongodb-org-mongos_4.0.0_amd64.deb /var/cache/apt /archives/mongodb-org-tools_4.0.0_amd64.deb E: 子进程/usr/bin/dpkg 返回错误码(1)

I believe the main problem is compatability with version. So basically I have Ubuntu 18.04, how I install mongodb on this version, so that I can work without any trouble.

我认为主要问题是与版本的兼容性。所以基本上我有 Ubuntu 18.04,我如何在这个版本上安装 mongodb,这样我就可以毫无问题地工作。

回答by Mohammad Umar

You need to first uninstall the mongodb, you can use:

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

sudo apt-get purge mongodb-org*

After this, install mongodb through the following commands:

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

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:

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

mongo --version

回答by rkumar-mongo

just want to chime in here. I'm the Senior Technical Writer for MongoDB Server Docs. This post is one of a few that comes up with "install MongoDB on Ubuntu 18.04", and there are several comments here referencing the mongodbpackage for installation. The unofficial mongodbpackage provided by Ubuntu is not maintained by MongoDB. You should always use the official MongoDB mongodb-orgpackages. Furthermore, from a bit of personal testing it looks like having mongodbinstalled will cause issues if you try to install mongodb-org, so its just added trouble

只想在这里插话。我是 MongoDB Server Docs 的高级技术作家。这篇文章是少数提出“在 Ubuntu 18.04 上安装 MongoDB”的文章之一,这里有几条评论引用了mongodb安装包。mongodbUbuntu 提供的非官方包不是由 MongoDB 维护的。您应该始终使用官方的 MongoDBmongodb-org包。此外,从一些个人测试来看,mongodb如果您尝试安装mongodb-org,安装似乎会导致问题,所以它只是增加了麻烦

The few times I've run into this issue when testing locally, attempting to install one of the subpackages (i.e. mongodb-org-server) usually surfaced the actual error (i.e. missing libcurl3, which was removed in 18.04 as a default installed library). These issues may be more common when testing development builds ( at the time of writing, that's the 4.2 dev series).

有几次我在本地测试时遇到这个问题,尝试安装其中一个子包(即mongodb-org-server)通常会出现实际错误(即 missing libcurl3,它在 18.04 中作为默认安装库被删除)。这些问题在测试开发构建时可能更常见(在撰写本文时,这是 4.2 开发系列)。

To check which package you have installed on your local system, run the following:

要检查您在本地系统上安装了哪个软件包,请运行以下命令:

sudo apt list --installed | grep mongo

This was my output after I installed mongodb, then attempted mongodb-org:

这是我安装后的输出mongodb,然后尝试mongodb-org

mongo-tools/bionic,now 3.6.3-0ubuntu1 amd64 [installed,auto-removable]
mongodb-org/bionic,now 4.0.5 amd64 [installed]
mongodb-org-shell/bionic,now 4.0.5 amd64 [installed,automatic]
mongodb-server-core/bionic,now 1:3.6.3-0ubuntu1 amd64 [installed,auto-removable]

So you can see, I've got a mix between the two packages (and a bunch of dkpgerrors). I ended up using a mix of apt remove, apt autoremove, and apt purgeto fix up the system.

所以你可以看到,我在两个包之间进行了混合(以及一堆dkpg错误)。我结束了使用的混合apt removeapt autoremove以及apt purge来修复系统。

回答by Ole Fass

This is because as of now Mongo DB for Ubuntu 18.04 is only available as a development version (See: MongoDB Distros).

这是因为到目前为止,Mongo DB for Ubuntu 18.04 仅作为开发版本提供(参见:MongoDB发行版)。

I just installed it by doing the following:

我只是通过执行以下操作来安装它:

Add the corresponding signature:

添加对应的签名:

    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4B7C549A058F8B6B  

Add the supported version:

添加支持的版本:

echo "deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/development multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list

Update:

更新:

    sudo apt update

Install:

安装:

sudo apt install mongodb-org-unstable

If you get a "GPG error" repeat step 1 with the key that is shown in the error message. You might be able to install via

如果您收到“GPG 错误”,请使用错误消息中显示的密钥重复步骤 1。您也许可以通过安装

sudo apt install mongodb

but according to MongoDB this is not supported and will most probably not install the newest version.

但根据 MongoDB 的说法,这不受支持,并且很可能不会安装最新版本。

回答by Kaushik Das

If you need to install mongodb binary (Manually) to your Ubuntu 18.04 LTS (Bionic). You need to download mongodb .tgz file from this link.

如果您需要将 mongodb 二进制文件(手动)安装到 Ubuntu 18.04 LTS(仿生)。您需要从此链接下载 mongodb .tgz 文件。

1) Download it to your ~/Downloads folder and moveit to home directory by typing mv Downloads/mongodb-linux-x86_64-ubuntu1804-4.0.4.tgz ~/

1) 将其下载到您的 ~/Downloads 文件夹并通过键入将其移动到主目录 mv Downloads/mongodb-linux-x86_64-ubuntu1804-4.0.4.tgz ~/

2) Then unter it by typing tar -zxvf mongodb-linux-x86_64-ubuntu1804-4.0.4.tgzplace it here (Home directory /home/). Dont move it from here.

2) 然后通过tar -zxvf mongodb-linux-x86_64-ubuntu1804-4.0.4.tgz在此处输入place it (Home directory /home/)来取消它。不要从这里移动它。

3) Then make a directory at /data/db location and give write permission to thatdirectory.

3) 然后在 /data/db 位置创建一个目录并授予对该目录的写权限。

sudo mkdir -p /data/db

sudo chmod -R 777 /data/db

4) Now, this is the tricky area. Make sure u r in hme directory by typing pwd (Present Working Directory)

4) 现在,这是一个棘手的领域。通过键入 pwd(当前工作目录)确保 ur 在 hme 目录中

pwd 

it will show

它会显示

/home/<your user name>

Then type

然后输入

ls -al

ls -al

This command will show up all hiddenfile at home directory and search for

此命令将显示主目录中的所有隐藏文件并搜索

~/.bashrc

~/.bashrc

5) Edit the .bashrc file and write

5)编辑.bashrc文件并写入

export PATH=mongodb-linux-x86_64-ubuntu1804-4.0.4/bin:$PATH

and save the file type source ./bashrc

并保存文件类型 source ./bashrc

Then type echo $PATHat terminal it will display ~/mongodb-linux-x86_64-ubuntu1804-4.0.4/bin:/home/xenon/.nvm/versions/node/v10.15.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin

然后echo $PATH在终端输入它会显示~/mongodb-linux-x86_64-ubuntu1804-4.0.4/bin:/home/xenon/.nvm/versions/node/v10.15.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin

6) Now at terminal type mongo --nodbit will show MongoDB shell version v4.0.4

6)现在在终端类型mongo --nodb它会显示MongoDB shell version v4.0.4

From here , you are all set, go ahead and enjoy mongodb installation. This istallation is bit complex but by this method you can easily control the version of mongodb and use it as per your need. enter image description here

从这里开始,您已准备就绪,继续享受 mongodb 安装。这个安装有点复杂,但通过这种方法,您可以轻松控制 mongodb 的版本并根据需要使用它。 在此处输入图片说明

7) Then start mongod

7)然后启动mongod

>sudo mkdir -p /var/log && sudo chmod -R 777 /var/log
>mongod --port 27017 --dbpath /data/db --logpath /var/log/local.log --fork
>mongo --port 27017

回答by Raystorm

Based on this excellent Answer: https://stackoverflow.com/a/51421152/659354

基于这个优秀的答案:https: //stackoverflow.com/a/51421152/659354

And this Page: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

还有这个页面:https: //docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

The commands I used to install MongoDB 4.2

我用来安装MongoDB 4.2的命令

sudo apt-get purge mongo*- Note:mongo to remove the client as well as the server.

sudo apt-get purge mongo*-注意:mongo 删除客户端和服务器。

sudo apt-get install mongodb-org- Note:install command run after the Mongodb.org Source was added to the Apt-get sources list.

sudo apt-get install mongodb-org-注意:安装命令在 Mongodb.org 源添加到 Apt-get 源列表后运行。

回答by Felipe Illanes

I had the same problem, and for me the solution was purge, but with the (*) . Purge everything, so i did this:

我遇到了同样的问题,对我来说,解决方案是清除,但使用 (*) 。清除所有内容,所以我这样做了:

sudo apt-get purge mongo-tools*
sudo apt-get purge mongodb*

then i follow the steps from the documentation. (Actual version is 4.2.2), and the installation was in Ubuntu 18.04. (URL: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/)

然后我按照文档中的步骤操作。(实际版本为4.2.2),安装在Ubuntu 18.04。(网址:https: //docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -

echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list

sudo apt-get update

sudo apt-get install -y mongodb-org

With that four steps from the documentation i finally install mongodb community edition on Ubuntu. My problem was 3 files,that can't process.

通过文档中的四个步骤,我终于在 Ubuntu 上安装了 mongodb 社区版。我的问题是 3 个文件,无法处理。

mongodb-org-server
mongodb-org-mongos
mongodb-org-tools

I hope its help someone

我希望它可以帮助某人

回答by Lord

Just run the command sudo apt install mongodbit will install the mongodb, because mongodb is now part of ubuntu repository. After installation run command sudo service mongodb startto start the mongodb server. Then if you run command mongoit will give you shell helper. To see the existing database use command show dbs. After successfull installation you will find there pre existing database names are admin, config, local. Use command dbto see which database is currently running on server, there will a database named test or somthing. To add a collection (tables on SQL DB) just use the insert command with an initial document (row in SQL DB) information db.data.insert({"username":"Brad Pitt"})
In previous command datais my collection name. Now to see all documents in data collection just use command db.data.find(); Other commands: sudo service mongod status, sudo service mongodb stop, sudo service mongod restart ,sudo service mongod stop.

只需运行命令sudo apt install mongodb它将安装 mongodb,因为 mongodb 现在是 ubuntu 存储库的一部分。安装后运行命令sudo service mongodb start启动 mongodb 服务器。然后,如果您运行命令 mongo,它将为您提供 shell 助手。要查看现有数据库,请使用命令 show dbs。成功安装后,您会发现预先存在的数据库名称为admin, config, local。使用命令db查看服务器上当前运行的是哪个数据库,会有一个名为test 或 somthing的数据库. 要添加集合(SQL DB 上的表),只需使用带有初始文档(SQL DB 中的行)信息的插入命令db.data.insert({"username":"Brad Pitt"})
在以前的命令中,数据是我的集合姓名。现在要查看数据集合中的所有文档,只需使用命令db.data.find();其他命令: sudo service mongod status、sudo service mongodb stop、sudo service mongod restart、sudo service mongod stop。

For more information, you can visit https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

更多信息,您可以访问https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

; enter image description here

; 在此处输入图片说明

enter image description here

在此处输入图片说明

回答by amyth

For Ubuntu version 18.04 LTS, it's better if you will install MongoDB manually.

对于 Ubuntu 18.04 LTS 版本,最好手动安装 MongoDB。

I need to go through the following steps to make it run on my Ubuntu 18.04:

我需要通过以下步骤使其在我的 Ubuntu 18.04 上运行:

  1. Fallow manual installation steps from the following mongo DB manual https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu-tarball/
  2. Download .tgz with the following configurations Download MongoDB
  3. Please note, when you install MongoDB 3.6 or above, it comes up with Curl library of "libcurl4" version and which has some compatibility issues on ubuntu 18.04
  4. Due to this, you will end up resulting following output when try to execute "mongod" command:
  1. 以下 mongo DB 手册https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu-tarball/ 中的休耕手动安装步骤
  2. 使用以下配置下载.tgz 下载 MongoDB
  3. 请注意,当您安装 MongoDB 3.6 或更高版本时,它会提供“libcurl4”版本的 Curl 库,并且在 ubuntu 18.04 上存在一些兼容性问题
  4. 因此,当尝试执行“mongod”命令时,您最终会得到以下输出:

mongod: /usr/lib/x86_64-linux-gnu/libcurl.so.4: version `CURL_OPENSSL_3' not found (required by mongod)

mongod:/usr/lib/x86_64-linux-gnu/libcurl.so.4:未找到版本“CURL_OPENSSL_3”(mongod 需要)

  1. To fix this problem, you need to uninstall "libcurl4" dependent library by using the following command

    sudo apt-get remove libcurl4

  2. Then need to install back lower curl lib version (i.e. "libcurl3"), as mongo expects it on ubuntu version "18.04"

    sudo apt-get install libcurl3

  3. You may need to use "sudo" to fork the data and log directories with the installation if it fails with the manual steps

    sudo mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --fork

  4. you can run "mongo" command now to see the mongo shell running.

  1. 要解决此问题,您需要使用以下命令卸载“libcurl4”依赖库

    sudo apt-get 删除 libcurl4

  2. 然后需要安装回较低的 curl lib 版本(即“libcurl3”),正如 mongo 在 ubuntu 版本“18.04”上所期望的那样

    须藤 apt-get 安装 libcurl3

  3. 如果手动步骤失败,您可能需要使用“sudo”在安装中分叉数据和日志目录

    须藤 mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --fork

  4. 您现在可以运行“mongo”命令来查看 mongo shell 正在运行。

It works for me.

这个对我有用。

回答by Qiang Zhang

run sudo apt autoremoveand re-install mongodb.

运行sudo apt autoremove并重新安装mongodb

回答by Michal S.

The easiest way to install MongoDB and use the mongodcommand on ubuntu 18.04.

mongod在 ubuntu 18.04 上安装 MongoDB 和使用命令的最简单方法。

1. Update the packages list.

1.更新包列表。

    $ sudo apt update

2. Install the MongoDB.

2. 安装MongoDB。

    $ sudo apt install -y mongodb

3. Check the service's status.

3. 检查服务状态。

    $ sudo systemctl status mongodb

3a. You should see

3a. 你应该看到

    ● mongodb.service - An object/document-oriented database
      Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor 
      preset:enabled)
      Active: active (running) since Sat 2019-03-11 10:45:01 UTC; 4min 13s ago
      Docs: man:mongod(1)
      Main PID: 2312 (mongod)
      Tasks: 23 (limit: 1153)
      CGroup: /system.slice/mongodb.service
            └─2312 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config
      /etc/mongodb.conf

4. To allow access to MongoDB on its default port 27017

4. 允许在默认情况下访问 MongoDB port 27017

     $ sudo ufw allow 27017

5. Check status

5.查看状态

     $ sudo ufw status

5a. You should see

5a. 你应该看到

     Status: active
     To                         Action      From
     --                         ------      ----
     27017                      ALLOW       Anywhere
     27017 (v6)                 ALLOW       Anywhere (v6)

5b. If it returns inactive

5b. 如果它返回inactive

     $ sudo ufw enable

     Output:
     Firewall is active and enabled on system startup.

6. Check the /directory to see if there is a data/dbdirectory, if not:

6.查看/目录,看是否有data/db目录,如果没有:

     $ sudo mkdir -p /data/db

7. To run the mongodfirst you need stop mongodb:

7. 要运行第mongod一个,您需要停止 mongodb:

     $ sudo systemctl stop mongodb

8. Finally, you can run the mongod:

8. 最后,您可以运行mongod

     $ sudo mongod

I hope that I helped

我希望我有所帮助