[英]Can't use mongo command, shows command not found on mac
I'm using Mac Lion.我正在使用 Mac Lion。 I was using mongodb version 1.4.
我使用的是 mongodb 1.4 版。 I wanted to upgrade to 1.8.5 and I followed http://shiftcommathree.com/articles/how-to-install-mongodb-on-os-x step wise replacing each mongodb-osx-x86_64-1.4.0 by mongodb-osx-x86_64-1.8.5.
我想升级到 1.8.5,我按照http://shiftcommathree.com/articles/how-to-install-mongodb-on-os-x一步一步用 mongodb 替换每个 mongodb-osx-x86_64-1.4.0- osx-x86_64-1.8.5。 Everything goes smooth.
一切顺利。 I tried:
我试过了:
mongod
it's ok.没关系。 I can access localhost:28017 but,
我可以访问 localhost:28017 但是,
mongo
shows command not found显示命令未找到
How can I fix this?我怎样才能解决这个问题?
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?你用paths.d做了最后一步吗? If so, try restarting your terminals.
如果是这样,请尝试重新启动终端。
Do you have a good reason for using 1.8.5?您有使用 1.8.5 的充分理由吗? The current stable is 2.0.4, and it has many useful upgrades from 1.8.x
当前的稳定版是 2.0.4,它从 1.8.x 有许多有用的升级
Starting from Mongodb version 6.0 mongo
was replaced by mongosh
从 Mongodb 版本开始 6.0
mongo
被mongosh
取代
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 变量永久化:
touch ~/.bash_profile
and then open ~/.bash_profile
.touch ~/.bash_profile
然后open ~/.bash_profile
。export PATH="<mongo-directory>/bin:$PATH"
(Keep the quote marks - related to white spaces).export PATH="<mongo-directory>/bin:$PATH"
(保留引号 - 与空格相关)。.bash_profile
file and Quit (Command + Q) Text Edit..bash_profile
文件并退出(Command + Q)文本编辑。source ~/.bash_profile
.source ~/.bash_profile
。echo $PATH
and check if the you see that the Mongo binary was added.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. (*) 请注意,PATH 变量现在仅可用于当前终端,而不能用于已在会话中启动的进程。
In order to make it available outside the current terminal - you'll have to logout and login.为了使其在当前终端之外可用 - 您必须注销并登录。
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
Note :笔记 :
If above command gives error如果上面的命令给出错误
Failed global initialization: BadValue Invalid or no user locale set.全局初始化失败:BadValue 无效或未设置用户区域设置。 Please ensure LANG and/or LC_ environment variables are set correctly.*
请确保正确设置 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
export PATH={mongodb-install-directory}/bin:$PATH
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.我面临同样的问题,这对我有用。
I didn't have the right mongo command line tools installed.我没有安装正确的 mongo 命令行工具。 This from Brew worked for me though.
不过,Brew 的这个对我有用。
brew install mongodb-community
In Mac:在 Mac 中:
Go into Bash Profile:进入 Bash 配置文件:
vi ~/.bash_profile
Add Path of Installation of MongoDB:添加MongoDB安装路径:
export PATH=$PATH:/usr/local/opt/mongodb-community@4.2/bin
Reload the Bash Profile:重新加载 Bash 配置文件:
source ~/.bash_profile
just a little recommandation, if your path has a space just wrap the whole path with quote or doublequote example : C:\Program Files\MongoDB\Server\4.2 .只是一点建议,如果您的路径有空格,只需用引号或双引号将整个路径括起来即可: C:\Program Files\MongoDB\Server\4.2 。 notice the space in "Program Files"
注意“程序文件”中的空格
export PATH=$PATH:"C:/Program Files/MongoDB/Server/X.X/bin"
in place of mongo command use mongosh command and it will work.使用 mongosh 命令代替 mongo 命令,它会起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.