简体   繁体   English

zsh:找不到命令:mongo

[英]zsh: command not found: mongo

I'm following the official instructions found here (on Mac OS Big Sur): https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/我遵循此处的官方说明(在 Mac OS Big Sur 上): https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/

When attempting to run mongo , I receive:尝试运行mongo时,我收到:

zsh: command not found: mongo

I then check if MongoDB is running by running:然后我通过运行检查 MongoDB 是否正在运行:

brew services start mongodb-community@4.4

I then receive:然后我收到:

Service mongodb-community@4.4 already started, use brew services restart mongodb-community@4.4 to restart

Because of this, I know MongoDB is running.因此,我知道 MongoDB 正在运行。 What gives?是什么赋予了? I followed the official instructions from MongoDB's website.我按照 MongoDB 网站的官方说明进行操作。

For Apple M1 Processor :对于Apple M1 处理器

If you install mongodb through Homebrew , follow the steps below:如果您通过Homebrew安装mongodb ,请按照以下步骤操作:

  1. Open up your Terminal打开你的Terminal

  2. Type brew list to check the formulae of the installed mongodb输入brew list查看已安装mongodb的公式

==> Formulae 
mongodb-community@4.4   mongodb-dxxx... 

==> Casks
xxxxx
  • In my case, it is mongodb-community@4.4 .就我而言,它是mongodb-community@4.4
  1. In the terminal, type brew list mongodb-community@4.4 to get the directory of the mongodb installed in your machine.在终端中,键入brew list mongodb-community@4.4以获取安装在您机器中的mongodb的目录。
/opt/homebrew/Cellar/mongodb-community@4.4/4.4.13/bin/install_compass
/opt/homebrew/Cellar/mongodb-community@4.4/4.4.13/bin/mongo
/opt/homebrew/Cellar/mongodb-community@4.4/4.4.13/bin/mongod
/opt/homebrew/Cellar/mongodb-community@4.4/4.4.13/bin/mongos
/opt/homebrew/Cellar/mongodb-community@4.4/4.4.13/homebrew.mxcl.mongodb-community@4.4.plist
/opt/homebrew/Cellar/mongodb-community@4.4/4.4.13/MPL-2
/opt/homebrew/Cellar/mongodb-community@4.4/4.4.13/THIRD-PARTY-NOTICES
  1. Copy the bin path of your mongodb: /opt/homebrew/Cellar/mongodb-community@4.4/4.4.13/bin复制 mongodb 的 bin 路径: /opt/homebrew/Cellar/mongodb-community@4.4/4.4.13/bin

  2. Open up your .zshrc file with any text-editor使用任何文本编辑器打开您的.zshrc文件

  3. Add this line to the file:将此行添加到文件中:

export PATH="/opt/homebrew/Cellar/mongodb-community@4.4/4.4.13/bin:${PATH}"
  1. Try mongo --version in your terminal, if you see similar output like shown below, you are good to go.在您的终端中尝试mongo --version ,如果您看到如下所示的类似输出,那么您就可以开始了。
MongoDB shell version v4.4.13
Build Info: {
    "version": "4.4.13",
    "gitVersion": "df25-----------b9246",
    "modules": [],
    "allocator": "system",
    "environment": {
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}
echo 'export PATH="/usr/local/opt/mongodb-community@4.4/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

I solved my problem with this command running on terminal but only path i added is diffrent Steps-我用在终端上运行的这个命令解决了我的问题,但我添加的唯一路径是不同的步骤 -

  1. brew list mongodb-community@4.0.酿造清单 mongodb-community@4.0. (run this first) (先运行这个)
  2. then copied - /opt/homebrew/Cellar/mongodb-community@4.0/4.0.28/bin.然后复制 - /opt/homebrew/Cellar/mongodb-community@4.0/4.0.28/bin。 this path这条路
  3. and executed并执行
    echo 'export PATH="/opt/homebrew/Cellar/mongodb-community@4.0/4.0.28/bin:$PATH"' >> ~/.zshrc source ~/.zshrc echo 'export PATH="/opt/homebrew/Cellar/mongodb-community@4.0/4.0.28/bin:$PATH"' >> ~/.zshrc source ~/.zshrc
  4. then i have checked by openning .zshrc file is my path has set on not by executing - nano .zshrc command然后我通过打开 .zshrc 文件检查了我的路径是不是通过执行-nano .zshrc 命令设置的

and it's done完成了

Thanks谢谢

I did the above procedures and it still didn't work.我做了上面的步骤,还是不行。 But I restarted my terminal using $exec bash -l and it works!但是我使用 $exec bash -l 重新启动了我的终端,它可以工作了!

I did the above procedures and it still didn't work.我做了上面的步骤,还是不行。 But use this, then it worked但是使用它,然后它就起作用了

brew install mongodb-community-shell brew install mongodb-community-shell

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

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