在 WSL 中安装 MongoDB [英] Installing MongoDB in WSL

查看:272
本文介绍了在 WSL 中安装 MongoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在看到 this 文档.但是 MongoDB 说:

I was trying to install MongoDB in WSL running Ubuntu 18.04 after seeing this documentation. But MongoDB says that:

重要
Ubuntu 提供的mongodb 包不是由MongoDB Inc. 维护的,并且与官方的mongodb-org 包冲突.如果你已经在你的 Ubuntu 系统上安装了 mongodb 包,你必须先卸载 mongodb 包,然后才能继续这些说明.

IMPORTANT
The mongodb package provided by Ubuntu is not maintained by MongoDB Inc. and conflicts with the official mongodb-org package. If you have already installed the mongodb package on your Ubuntu system, you must first uninstall the mongodb package before proceeding with these instructions.

MongoDB 还说 WSL 不支持 mongodb-org

MongoDB also says that WSL doesn't support mongodb-org

WINDOWS SUBSYSTEM FOR LINUX (WSL) - 不支持
MongoDB 不支持 Windows Subsystem for Linux (WSL).

WINDOWS SUBSYSTEM FOR LINUX (WSL) - UNSUPPORTED
MongoDB does not support the Windows Subsystem for Linux (WSL).

所以,我使用 sudo apt install mongodb 安装了 mongod,当我运行 mongo 时,它显示错误:

So, I installed mongod using sudo apt install mongodb and when I ran mongo it shows the error:

connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
2020-06-21T13:33:40.606+0530 E  QUERY    [js] Error: couldn't connect to server 127.0.0.1:27017

有没有办法安装合适的包并让它运行?

Is there is a way to install the appropriate package and make it running?

推荐答案

我最近遇到了这种情况.

I have come across this situation recently.

尽管 MongoDB 说 WSL 不支持它,但您实际上可以安装它.因此,我建议您按照 MongoDB 文档中给出的步骤进行操作.

Even though MongoDB says that it is not supported in WSL, you can actually install it. So, I suggest you follow that steps given in MongoDB docs.

注意:如果你已经安装了 mongodb,请在安装 mongodb-org 之前删除所有这些,因为它可能会导致安装过程中出现一些问题:

Note : If you have already installed mongodb please remove all those before you install mongodb-org since it may cause some issues during installation :

sudo dpkg --remove --force-remove-reinstreq mongo-tools
sudo dpkg --remove --force-remove-reinstreq mongodb-server-core
sudo apt-get --fix-broken install

为了安装 mongodb 社区版,我添加了以下命令:

For installing mongodb community edition, I have added the commands below:

wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
sudo apt-get install gnupg
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] 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

现在,要运行 mongoDB,

Now, to get mongoDB running,

sudo nano /etc/init.d/mongod

并将此链接中的内容粘贴到文件中并保存.

and paste the contents in this link into the file and save it.

#give permissions
sudo chmod +x /etc/init.d/mongod

#start the service
sudo service mongod start

现在,您可以运行 mongo 来访问数据库.

Now, you can run mongo to reach the database.

希望有帮助.

这篇关于在 WSL 中安装 MongoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆