如何在Mac OSX上将mongo命令添加到PATH [英] How to add mongo commands to PATH on Mac OSX
问题描述
我正在使用 https://university.mongodb.com/(顺便说一句,很棒的材料),但是我无法将mongo命令添加到我的路径中.
I'm using MongoDb 2.6.1 following the material from https://university.mongodb.com/ (great material by the way) but I am not being able to add to my path the mongo commands.
我已遵循本指南 http://docs .mongodb.org/manual/tutorial/install-mongodb-on-os-x/,我这样修改了.bashrc
I've followed this guide http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/ and I modified my .bashrc like this
export PATH=/Users/jonathancaballero/bin/mongodb/mongodb_2.6.1/bin:$PATH
确实存在二进制文件的位置(直接使用查找程序检查)
And there is indeed where the binaries are (checked using the finder directly)
所以我的问题是为什么我不能从终端的任何位置使用mongod?
推荐答案
请将PATH
导出文件放入.bash_profile
:
export PATH=/path/to/your/mongo/bin:$PATH
将其放入.bash_profile
的原因是,当bash作为登录外壳程序启动时,通常会执行该文件,而对于交互式非登录外壳程序,通常会摘除.bashrc
.通常发生的情况是.bashrc
来自.bash_profile
.这里似乎并非如此.在MacOS X上,当您启动终端时,不会执行.bashrc
.上帝知道为什么,因为打开的外壳应该是交互式非登录外壳,因此应该执行.bashrc
.
The reason to put it into .bash_profile
is that this file will usually get executed when bash is started as a login shell while .bashrc
usually is exectuted for interactive non-login-shells. What usually happens is that .bashrc
gets sourced in .bash_profile
. This does not seem to be the case here. On MacOS X when you start a Terminal, .bashrc
does not get executed. God knows why, as the shell opened should be an interactive non-login shell and therefor should execute .bashrc
.
另一种,尽管更具侵入性"的解决方案是将以下内容添加到.bash_profile
.
Another, albeit more "intrusive" solution would be to add the following to .bash_profile
.
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
For those who are interested in the details: take a look into the according sections of bash's manpage
这篇关于如何在Mac OSX上将mongo命令添加到PATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!