mongodb Mongod:找不到命令 (OS X)

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

Mongod: Command Not Found (OS X)

macosmongodb

提问by MissElizabeth

I am trying to test MongoDB and I have it all downloaded and moved into the root folder. I can navigate to the folder that holds the mongod, but when I try to run it by typing "mongod" into my terminal, I get a message that says:

我正在尝试测试 MongoDB,我已将其全部下载并移动到根文件夹中。我可以导航到包含 mongod 的文件夹,但是当我尝试通过在终端中键入“mongod”来运行它时,我收到一条消息:

"mongod: command not found"

“mongod:找不到命令”

回答by Laurent Jacquot

Both answers above are correct. You can either specify the path in one of the following files: .profile, .bashrc, or .bash_profile

以上两个答案都是正确的。您可以在以下文件之一中指定路径:.profile、.bashrc 或 .bash_profile

export PATH="$PATH:/usr/local/mongodb/bin"

then call the daemon or the shell directly

然后直接调用守护进程或shell

mongod
mongo

Or for the commands not in the $PATH, use ./mongo or ./mongod from the directory containing these files. This solution can be verbose has you will have to eventually append the whole path when calling these commands from another directory.

或者对于不在 $PATH 中的命令,使用包含这些文件的目录中的 ./mongo 或 ./mongod 。此解决方案可能很冗长,因为在从另一个目录调用这些命令时,您最终必须附加整个路径。

/usr/local/mongodb/bin/mongod
or
/usr/local/mongodb/bin$ ./mongod 

回答by MissElizabeth

"Mongod" isn't a stand-alone command. You need to run the command like this:

“Mongod”不是一个独立的命令。您需要像这样运行命令:

./mongodb/bin/mongod

I used this webpageto help me answer this question.

我用这个网页来帮助我回答这个问题。

回答by Mark Setchell

You need to add the name of the folder that contains the command mongodinto your PATH so your shell knows where to find it.

您需要将包含该命令的文件夹的名称添加mongod到您的 PATH 中,以便您的 shell 知道在哪里可以找到它。

So, if mongodis in /usr/bin/freddyfrog, you would edit ~/.profileand find the line that says PATH=and edit it to look like this:

因此,如果mongod在 /usr/bin/freddyfrog 中,您将编辑~/.profile并找到显示的行PATH=并将其编辑为如下所示:

export PATH=${PATH}:/usr/bin/freddyfrog

Then login again to make it take effect.

然后再次登录使其生效。

回答by Haddad

3 steps:

3个步骤:

Step 1:

第1步:

export PATH="$PATH:/usr/local/mongodb/bin"

OR

或者

export PATH="$PATH:/usr/local/opt/[email protected]/bin"

(replace version number with your local version)

(将版本号替换为您的本地版本)

The first step will allow you to run the command, but will get you another error: "/data/db does not exit" so you have to

第一步将允许您运行该命令,但会给您带来另一个错误:“/data/db does not exit”所以您必须

Step 2 :

第2步 :

sudo mkdir -p /data/db

Now /data/db is read only, but it has to be writable also so

现在 /data/db 是只读的,但它也必须是可写的,所以

Step 3 :

第 3 步:

sudo chown -R USERNAME /data/db 

回答by shilovk

For example install 32bit MongoDB 2.6.12 on macOS Catalina. (for newest versions you may go to https://www.mongodb.com/download-center/communityfor your platform).

例如在 macOS Catalina 上安装 32 位 MongoDB 2.6.12。(对于最新版本,您可以为您的平台访问https://www.mongodb.com/download-center/community)。

  1. Download, extract and move:

    wget http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.6.12.tgz

    tar xzf mongodb-osx-x86_64-2.6.12.tgz

    mv mongodb-osx-x86_64-2.6.12/ /usr/local/mongodb/

  2. Add to file ~/.zshrcthis:

    export PATH="$PATH:/usr/local/mongodb/bin"

    PS: .bash_profileor .profilenot worked in my case

  3. Make directory for data and set rights:

    mkdir -p ~/data/db

    chown -R mongodb.mongodb ~/data/db

  4. Run MongoDB:

    mongod --dbpath ~/data/db

  1. 下载、解压和移动:

    wget http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.6.12.tgz

    tar xzf mongodb-osx-x86_64-2.6.12.tgz

    mv mongodb-osx-x86_64-2.6.12/ /usr/local/mongodb/

  2. 添加到文件~/.zshrc

    export PATH="$PATH:/usr/local/mongodb/bin"

    PS:.bash_profile.profile在我的情况下不起作用

  3. 为数据创建目录并设置权限:

    mkdir -p ~/data/db

    chown -R mongodb.mongodb ~/data/db

  4. 运行 MongoDB:

    mongod --dbpath ~/data/db

回答by Cesar Gamboa Avellan

This worked for me:

这对我有用:

  1. brew tap mongodb/brew
  2. brew install [email protected]
  3. mongod
  1. 酿造自来水mongodb/酿造
  2. 酿造安装 [email protected]
  3. 蒙哥

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/

回答by Ahmed Younes

In root directory

在根目录

sudo mkdir data
cd data 
mkdir db

then

然后

sudo chown -R yourUsername /data/ 

copy path of your mongodb/bin downloaded folder(I suggest you put it in home folder not root dir)

复制你的 mongodb/bin下载文件夹的路径 (我建议你把它放在主文件夹而不是根目录中)

enter image description here

在此处输入图片说明

in terminal

在终端

export PATH="paste the link here :$PATH"

export PATH="在此处粘贴链接:$PATH"

now it should work but if not

现在它应该工作,但如果没有

In case you are using different Unix shell and trying to execute mongod within visual studio code( for example ), make sure to read the documentation to link PATH.

如果您使用不同的 Unix shell 并尝试在 Visual Studio 代码(例如)中执行 mongod,请务必阅读文档以链接 PATH。

For example, if you are using zshcreate .zprofile in your home directory.

例如,如果您在主目录中使用zshcreate .zprofile。

touch .zprofile

touch .zprofile

copy your previously made PATH into .zprofile

将您之前制作的 PATH 复制到 .zprofile

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

Now everything should work as expected.

现在一切都应该按预期工作。

回答by Muhammad Amir

run this command, it works:

运行这个命令,它的工作原理:

brew services start [email protected]

brew services start [email protected]

回答by Kushagr Arora

I was trying to install a previous version (3.6) using latest documentation (4.2 is already released). So, they now call it [email protected].

我试图使用最新的文档(4.2 已经发布)安装以前的版本 (3.6)。所以,他们现在称之为[email protected]

In order to update PATH for such setup, the statement should be

为了更新此类设置的 PATH,语句应该是

export PATH="$PATH:/usr/local/opt/[email protected]/bin";

I got hint from @retroGiant 's answer

我从@retroGiant 的回答中得到了提示