简体   繁体   English

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

[英]Unable to install mongodb properly on ubuntu 18.04 LTS

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.您可能需要运行 'apt --fix-broken install' 来纠正这些问题。 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.以下软件包具有未满足的依赖关系:mongodb-org:依赖:mongodb-org-server 但不会安装依赖:mongodb-org-mongos 但不会安装依赖:mongodb-org-tools 但它不会安装 E:未满足的依赖项。 Try 'apt --fix-broken install' with no packages (or specify a solution).尝试不带软件包的“apt --fix-broken install”(或指定解决方案)。 umar@umar-Lenovo-ideapad-320-15ISK:~/Desktop/portfolio/async-demo$ sudo apt-get install -y mongodb 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; MongoDB 仅提供 64 位 LTS(长期支持)Ubuntu 版本的软件包; for example, 14.04 LTS (trusty) and 16.04 LTS (xenial).例如,14.04 LTS(可信)和 16.04 LTS(xenial)。 See Supported Platforms for more information.有关详细信息,请参阅支持的平台。

These packages may work with other Ubuntu releases;这些软件包可以与其他 Ubuntu 版本一起使用; however, they are not supported.但是,它们不受支持。

So how can I install mongodb on my latest Ubuntu 18.04 LTS?那么如何在我最新的 Ubuntu 18.04 LTS 上安装 mongodb? For sake of clarity, I am listing the things I did to correct the errors: I followed their official website to install 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.现在在这里我收到错误消息:您可能需要运行 'apt --fix-broken install' 来纠正这些错误。 The following packages have unmet dependencies:以下包具有未满足的依赖项:

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,这样我就可以毫无问题地工作了。

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.您已完成 mongodb 的安装。 You can check it by using the below command:您可以使用以下命令进行检查:

mongo --version

just want to chime in here.只想在这里插话。 I'm the Senior Technical Writer for MongoDB Server Docs.我是 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 mongodb package for installation.这篇文章是“在 Ubuntu 18.04 上安装 MongoDB”的少数文章之一,这里有几条评论引用了mongodb包进行安装。 The unofficial mongodb package provided by Ubuntu is not maintained by MongoDB. Ubuntu 提供的非官方mongodb包不由 MongoDB 维护。 You should always use the official MongoDB mongodb-org packages.您应该始终使用官方的 MongoDB mongodb-org包。 Furthermore, from a bit of personal testing it looks like having mongodb installed will cause issues if you try to install mongodb-org , so its just added trouble此外,从一些个人测试看来,如果您尝试安装mongodb mongodb-org ,安装 mongodb 会导致问题,所以它只会增加麻烦

The few times I've run into this issue when testing locally, attempting to install one of the subpackages (ie mongodb-org-server ) usually surfaced the actual error (ie missing libcurl3 , which was removed in 18.04 as a default installed library).有几次我在本地测试时遇到这个问题,尝试安装其中一个子包(即mongodb-org-server )通常会出现实际错误(即缺少libcurl3 ,它在 18.04 中作为默认安装的库被删除) . These issues may be more common when testing development builds ( at the time of writing, that's the 4.2 dev series).在测试开发版本时,这些问题可能更常见(在撰写本文时,这是 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 dkpg errors).所以你可以看到,我混合了这两个包(以及一堆dkpg错误)。 I ended up using a mix of apt remove , apt autoremove , and apt purge to fix up the system.我最终混合使用了apt removeapt autoremoveapt purge来修复系统。

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 源列表后运行。

This is because as of now Mongo DB for Ubuntu 18.04 is only available as a development version (See: MongoDB Distros ).这是因为到目前为止,适用于 Ubuntu 18.04 的 Mongo DB 仅作为开发版本提供(参见: MongoDB Distros )。

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.如果您收到“GPG 错误”,请使用错误消息中显示的密钥重复步骤 1。 You might be able to install via您也许可以通过安装

sudo apt install mongodb

but according to MongoDB this is not supported and will most probably not install the newest version.但根据 MongoDB,这不受支持,很可能不会安装最新版本。

The easiest way to install MongoDB and use the mongod command on ubuntu 18.04.在 ubuntu 18.04 上安装 MongoDB 和使用mongod命令的最简单方法。

  1. Update the packages list.更新软件包列表。

     $ sudo apt update
  2. Install the MongoDB.安装 MongoDB。

     $ sudo apt install -y mongodb
  3. Check the service's status.检查服务的状态。

     $ sudo systemctl status mongodb

    3a. 3a。 You should see你应该看到

     ● 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允许在其默认port 27017上访问 MongoDB

     $ sudo ufw allow 27017
  5. Check status检查状态

     $ sudo ufw status

5a. 5a。 You should see你应该看到

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

5b. 5b。 If it returns inactive如果它返回inactive

     $ sudo ufw enable

     Output:
     Firewall is active and enabled on system startup.
  1. Check the / directory to see if there is a data/db directory, if not:检查/目录看是否有data/db目录,如果没有:

     $ sudo mkdir -p /data/db
  2. To run the mongod first you need stop mongodb:要首先运行mongod ,您需要停止 mongodb:

     $ sudo systemctl stop mongodb
  3. Finally, you can run the mongod :最后,您可以运行mongod

     $ sudo mongod

cd /etc/apt/sources.list.d

remove files related to mongodb删除与 mongodb 相关的文件

sudo apt update

This solved it for me.这为我解决了。

Uninstall and remove any Mongo packages.卸载并删除任何 Mongo 包。

$ sudo apt-get purge mongodb-org*

Check if related directories removed检查是否删除了相关目录

$ sudo rm -r /var/log/mongodb
$ sudo rm -r /var/lib/mongodb

Recheck for autoremove any remaining mongo packages重新检查自动删除任何剩余的 mongo 包

$ sudo apt-get autoremove

Configure your directory配置你的目录

$ sudo dpkg --configure -a

Force install anything required强制安装任何需要的东西

$ sudo apt-get install -f

Install from official site: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/从官方网站安装: https ://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

Finally restart your Ubuntu and check status of Mogodb server as you did earlier.最后重新启动您的 Ubuntu 并像之前一样检查 Mogodb 服务器的状态。

If you need to install mongodb binary (Manually) to your Ubuntu 18.04 LTS (Bionic).如果您需要将 mongodb 二进制文件(手动)安装到 Ubuntu 18.04 LTS(仿生)。 You need to download mongodb .tgz file from this link .您需要从此链接下载 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.tgz place it here (Home directory /home/). 2)然后通过键入tar -zxvf mongodb-linux-x86_64-ubuntu1804-4.0.4.tgz将其放置在这里(主目录/home/)。 Dont move it from here.不要从这里移动它。

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. 4)现在,这是一个棘手的领域。 Make sure ur in hme directory by typing pwd (Present Working Directory)通过键入 pwd(当前工作目录)确保您在 hme 目录中

pwd 

it will show它会显示

/home/<your user name>

Then type然后输入

ls -al

This command will show up all hiddenfile at home directory and search for此命令将显示主目录中的所有隐藏文件并搜索

~/.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 $PATH at 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 --nodb it 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.从这里开始,一切就绪,继续享受 mongodb 安装。 This istallation is bit complex but by this method you can easily control the version of mongodb and use it as per your need.这种安装有点复杂,但是通过这种方法,您可以轻松控制 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

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. (实际版本是4.2.2),安装在Ubuntu 18.04。 (URL: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/ ) (网址: 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.通过文档中的这四个步骤,我终于在 Ubuntu 上安装了 mongodb 社区版。 My problem was 3 files,that can't process.我的问题是 3 个文件,无法处理。

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

I hope its help someone我希望它对某人有帮助

运行sudo apt autoremove并重新安装mongodb

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/以下 mongo DB 手册https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu-tarball/中的手动安装步骤
  2. Download .tgz with the following configurations Download MongoDB使用以下配置下载 .tgz下载 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请注意,当您安装 MongoDB 3.6 或更高版本时,它会附带“libcurl4”版本的 Curl 库,并且在 ubuntu 18.04 上存在一些兼容性问题
  4. Due to this, you will end up resulting following output when try to execute "mongod" command:因此,当您尝试执行“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要解决此问题,您需要使用以下命令卸载“libcurl4”依赖库

    sudo apt-get remove libcurl4 sudo apt-get 删除 libcurl4

  2. Then need to install back lower curl lib version (ie "libcurl3"), as mongo expects it on ubuntu version "18.04"然后需要安装回较低的 curl lib 版本(即“libcurl3”),因为 mongo 期望它在 ubuntu 版本“18.04”上

    sudo apt-get install libcurl3 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”在安装过程中分叉数据和日志目录

    sudo mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --fork 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.您现在可以运行“mongo”命令来查看 mongo shell 正在运行。

It works for me.这个对我有用。

This issue is only on Ubuntu 22.04 ,此问题仅在Ubuntu 22.04上,

Try this out:试试这个:

echo "deb http://security.ubuntu.com/ubuntu impish-security main" | sudo tee /etc/apt/sources.list.d/impish-security.list

sudo apt-get update

sudo apt-get install libssl1.1

Just run the command sudo apt install mongodb it will install the mongodb, because mongodb is now part of ubuntu repository.只需运行命令sudo apt install mongodb它将安装 mongodb,因为 mongodb 现在是 ubuntu 存储库的一部分。 After installation run command sudo service mongodb start to start the mongodb server.安装后运行命令sudo service mongodb start启动 mongodb 服务器。 Then if you run command mongo it will give you shell helper.然后,如果您运行命令mongo ,它将为您提供 shell 助手。 To see the existing database use command show dbs .要查看现有数据库,请使用命令show dbs After successfull installation you will find there pre existing database names are admin, config, local .成功安装后,您会发现已有的数据库名称为admin、config、local Use command db to see which database is currently running on server, there will a database named test or somthing .使用命令db查看当前在服务器上运行的数据库,会有一个名为test 或 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"})要添加集合(SQL DB 上的表),只需使用带有初始文档(SQL DB 中的行)信息的插入命令db.data.insert({"username":"Brad Pitt"})
In previous command data is my collection name.在前面的命令中,数据是我的集合名称。 Now to see all documents in data collection just use command db.data.find() ;现在要查看数据收集中的所有文档,只需使用命令db.data.find() Other commands: sudo service mongod status, sudo service mongodb stop, sudo service mongod restart ,sudo service mongod stop.其他命令: 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/

; ; 在此处输入图像描述

在此处输入图像描述

For me on Pop_OS Linux 20.04 LTS helped:对我来说,Pop_OS Linux 20.04 LTS 帮助:

  1. $ sudo apt-get purge mongodb*

Then creating /etc/apt/sources.list.d/mongodb-org-4.4.list file for Ubuntu 18.04 (Bionic) via this command:然后通过以下命令为 Ubuntu 18.04 (Bionic) 创建/etc/apt/sources.list.d/mongodb-org-4.4.list文件:

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

instead of Ubuntu 20.04 (Focal)而不是 Ubuntu 20.04 (Focal)

After that install mongodb-org:之后安装 mongodb-org:

  1. $ sudo apt-get update
    $ sudo apt-get install -y mongodb-org

And start mongodb service:并启动 mongodb 服务:

  1. $ sudo systemctl start mongod

I was facing a libssl1.1 issue when trying to install mongo-db in Pop._OS 22.04 LTS (or Ubuntu 22.04 LTS).尝试在 Pop._OS 22.04 LTS(或 Ubuntu 22.04 LTS)中安装 mongo-db 时,我遇到了 libssl1.1 问题。

  1. Go to http://archive.ubuntu.com/ubuntu/pool/main/o/openssl Go 到http://archive.ubuntu.com/ubuntu/pool/main/o/openssl
  2. Find the exact version of libssl for example libssl1.1.1查找 libssl 的确切版本,例如 libssl1.1.1
  3. wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1-1ubuntu2.1~18.04.20_amd64.deb wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1-1ubuntu2.1~18.04.20_amd64.deb
  4. Then install然后安装
  5. sudo dpkg -i libssl1.1_1.1.1-1ubuntu2.1~18.04.20_amd64.deb sudo dpkg -i libssl1.1_1.1.1-1ubuntu2.1~18.04.20_amd64.deb

Hope this helps others who are trying to do the same.希望这可以帮助其他正在尝试做同样事情的人。

The issue is referenced in https://github.com/dotnet/sdk/issues/24759 . https://github.com/dotnet/sdk/issues/24759中引用了该问题。

All credit goes to @feisalramar.所有功劳归@feisalramar。

试试这个,我成功找到了

$ sudo apt-get install -y mongodb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM