通过 Homebrew 安装的 MongoDB 不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11707938/
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-09 12:46:07  来源:igfitidea点击:

MongoDB installed via Homebrew not working

macosmongodbhomebrew

提问by webgirl

I installed MongoDB via Homebrew (following http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/) but it's not working.

我通过 Homebrew 安装了 MongoDB(遵循http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/)但它不起作用。

Typing mongodat shell prompt gives me:

mongod在 shell 提示符下输入给我:

-bash: mongod: command not found

Not sure if I need to add something for Homebrew to my PATH env var?

不确定我是否需要为 Homebrew 添加一些东西到我的 PATH 环境变量?

I can see Mongo is installed under /usr/local/Cellar/mongodb– but am assuming I don't need to add everything I install via homebrew to the path? Also, assuming I can run mongod from any directory or am I actually meant to be in install directory?

我可以看到 Mongo 安装在下面/usr/local/Cellar/mongodb——但我假设我不需要将我通过自制软件安装的所有东西都添加到路径中?另外,假设我可以从任何目录运行 mongod 还是我实际上打算在安装目录中?

When I run brew doctorI get:

当我运行时,brew doctor我得到:

Warning: You have unlinked kegs in your Cellar 

Followed by a list of 3 items which includes MongoDB – but I'm not sure how I'm meant to link them?

接下来是包含 MongoDB 的 3 个项目的列表——但我不确定我打算如何链接它们?

回答by Den

Works perfectly

完美运行

  1. brew update
  2. brew tap mongodb/brew
  3. brew install [email protected]
  1. brew update
  2. brew tap mongodb/brew
  3. brew install [email protected]

For latest version, check https://docs.mongodb.com/manual/release-notes/

对于最新版本,请查看https://docs.mongodb.com/manual/release-notes/

回答by William Z

You're getting this error because your 'brew' install failed to create the correct symlinks in /usr/local/bin. As a result, the shell can't find the mongo executables in your $PATH. You can fix this using the following steps:

您收到此错误是因为您的“brew”安装未能在 /usr/local/bin 中创建正确的符号链接。因此,shell 在您的 $PATH 中找不到 mongo 可执行文件。您可以使用以下步骤修复此问题:

  • Check the permissions on /usr/local/bin and make sure that you own that directory and have write permissions on it

    $ ls -ld /usr/local/bin

  • Once you've fixed that, run 'brew link' to fix the symlinks

    $ brew link mongodb

  • 检查 /usr/local/bin 上的权限并确保您拥有该目录并对其具有写权限

    $ ls -ld /usr/local/bin

  • 一旦你解决了这个问题,运行'brew link'来修复符号链接

    $ brew link mongodb

回答by iBaff

If you are on [email protected]. You can try to reinstall with brew reinstall [email protected].

如果您在[email protected]. 您可以尝试重新安装brew reinstall [email protected]

Then I get the following hint:

然后我得到以下提示:

==> Caveats
[email protected] is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have [email protected] first in your PATH run:
  echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile

So you can just copy the echocommand and restart your shell!

所以你可以复制echo命令并重新启动你的shell!

回答by Sammaye

It works from the directory since the sh searches the ENV path and then the cwd for a program named mongod. I have been looking around a little and it seems that the default install of MongoDB (I am not a Mac user) does not install a rc or init script for which sh to understand it's running behaviour as stated here:

它从目录开始工作,因为 sh 搜索 ENV 路径,然后搜索名为 mongod 的程序的 cwd。我一直在环顾四周,似乎 MongoDB 的默认安装(我不是 Mac 用户)没有安装 rc 或 init 脚本,sh 以了解它的运行行为,如下所述:

http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/#using-mongodb-from-homebrew-and-macports

http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/#using-mongodb-from-homebrew-and-macports

The packages installed with Homebrew and MacPorts contain no control scripts or interaction with the system's process manager.

If you have configured Homebrew and MacPorts correctly, including setting your PATH, the MongoDB applications and utilities will be accessible from the system shell. Start the mongod process in a terminal (for testing or development) or using a process management tool.

随 Homebrew 和 MacPorts 安装的软件包不包含控制脚本或与系统进程管理器的交互。

如果您已正确配置 Homebrew 和 MacPorts,包括设置 PATH,则可以从系统外壳访问 MongoDB 应用程序和实用程序。在终端(用于测试或开发)或使用进程管理工具启动 mongod 进程。

So you must actually define (as you said) MongoDBs path, here is an example: https://snipt.net/sido/installing-mongodb-on-os-x/

所以你必须实际定义(如你所说)MongoDBs 路径,这里是一个例子:https://snipt.net/sido/installing-mongodb-on-os-x/

Edit: the example is not mine. I just stole it from it's user: https://snipt.net/sido/

编辑:这个例子不是我的。我只是从它的用户那里偷了它:https: //snipt.net/sido/