mongodb 无法使用 mongo 命令,显示在 mac 上找不到命令

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

cant use mongo command, shows command not found on mac

macosmongodb

提问by Ajay

I am using Mac Lion. I was using mongodb version 1.4. i wanted to upgrade to 1.8.5 I followed http://shiftcommathree.com/articles/how-to-install-mongodb-on-os-xstep wise replacing each mongodb-osx-x86_64-1.4.0 by mongodb-osx-x86_64-1.8.5. everything goes smooth. I tried:

我正在使用 Mac Lion。我使用的是 mongodb 1.4 版。我想升级到 1.8.5 我跟着http://shiftcommathree.com/articles/how-to-install-mongodb-on-os-x逐步替换每个 mongodb-osx-x86_64-1.4.0 由 mongodb-osx -x86_64-1.8.5。一切顺利。我试过:

mongod 

its ok. I can access localhost:28017 but,

没关系。我可以访问 localhost:28017 但是,

mongo

shows command not found

显示未找到命令

how i can i fix this

我该如何解决这个问题

回答by Eve Freeman

You need to add the path to "mongo" to your terminal shell.

您需要将“mongo”的路径添加到终端外壳中。

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

Did you do the last step with paths.d? If so, try restarting your terminals.

你用paths.d做最后一步了吗?如果是这样,请尝试重新启动终端。

Do you have a good reason for using 1.8.5? The current stable is 2.0.4, and it has many useful upgrades from 1.8.x

您有使用 1.8.5 的充分理由吗?当前的稳定版是 2.0.4,从 1.8.x 开始有很多有用的升级

回答by Nanhe Kumar

1.Go to your [mongodb installation dir]:

1.转到你的[mongodb安装目录]:

cd <mongodb installation dir>

2.Type ./bin/mongo to start mongo:

2.输入./bin/mongo启动mongo:

./bin/mongo

Read More

阅读更多

Note :

笔记 :

If above command gives error

如果上面的命令给出错误

Failed global initialization: BadValue Invalid or no user locale set. Please ensure LANG and/or LC_environment variables are set correctly.*

全局初始化失败:BadValue 无效或未设置用户区域设置。请确保 LANG 和/或 LC_环境变量设置正确。*

Run bellow command: Read More

运行波纹管命令:阅读更多

export LC_ALL=C

How can find installation directory

怎么找到安装目录

find / -name "mongodb" 

You can also set path

也可以设置路径

export PATH=$PATH:<mongodb installation dir>/bin

回答by Dimitar Dimitrov

documentation

文件

export PATH={mongodb-install-directory}/bin:$PATH

回答by Siddhant Saxena

You can navigate to the mongo directory using the command line and then start MongoDB with

您可以使用命令行导航到 mongo 目录,然后使用以下命令启动 MongoDB

./mongodb

I was facing the same problem this worked for me.

我面临着同样的问题,这对我有用。

回答by RtmY

You'll have to add the location of the Mongo binary to PATH.

您必须将 Mongo 二进制文件的位置添加到 PATH。

Follow the steps below in order to make the PATH variable permanent:

请按照以下步骤使 PATH 变量永久化:

  1. Open Terminal and navigate to your user directory.
  2. Run touch ~/.bash_profileand then open ~/.bash_profile.
  3. In TextEdit, add export PATH="<mongo-directory>/bin:$PATH"(Keep the quote marks - related to white spaces).
  4. Save the .bash_profilefile and Quit (Command + Q) Text Edit.
  5. Run source ~/.bash_profile.
  6. Run echo $PATHand check if the you see that the Mongo binarywas added.
  1. 打开终端并导航到您的用户目录。
  2. 运行touch ~/.bash_profile然后 open ~/.bash_profile
  3. 在 TextEdit 中,添加export PATH="<mongo-directory>/bin:$PATH"(保留引号 - 与空格相关)。
  4. 保存.bash_profile文件并退出(Command + Q)文本编辑。
  5. 运行source ~/.bash_profile
  6. 运行echo $PATH并检查您是否看到添加了Mongo 二进制文件

(*) Notice that the PATH variable is now available only for the current terminal and not to processes that were already started in the session.
In order to make it available outside the current terminal - you'll have to logout and login.

(*) 请注意,PATH 变量现在仅可用于当前终端,而不可用于会话中已启动的进程。
为了使其在当前终端之外可用 - 您必须注销并登录。