How do I ensure that Mongo binaries are in my PATH - in my shell' rc (~/.bashrc) on a Mac
When you download MongoDB for Mac, you get an archive file. First thing you need to is uncompress the archive. To do that you just double click on the archive. The uncompressed folder will have the binaries in the bin
folder, like mongodb-osx-x86_64-2.6.7/bin
. What you need to do next is to make sure these binaries are accessible. So, for this you can do either of the two things -
Copy the binaries to
/usr/local/bin
folder. As/usr/local/bin
is always in PATH, so you don't have to add it to the PATH.This is pretty simple. Run
cp mongodb-osx-x86_64-2.6.7/bin/* /usr/local/bin/
. That's it. You are all done.Add the binary folder's path to your
$PATH
variable.Open the
.bashrc
file, which is located in your home folder, and putexport PATH=$HOME/mongodb/bin:$PATH
line in the end. I am assuming that mongodb uncompressed in downloads.
If going by the second method, make sure you don't accidently delete the mongodb folder that is added in the PATH.
Once you have finished doing this, close the terminal, open a new terminal window and run:
mongo --version
If you get the mongodb info with version, then good.
If you still get something like command mongo not found
, then make sure you followed above instructions right. Also make sure you are not using any other shell, like zsh. If you are, then you have to add the export
statement in the respective shell file. For zsh the file name is .zshrc
.
Okay! So as you have updated the initial question with some more questions. So here goes the explanation point by point:
The files you see in
/usr/local/bin
folder are binaries. In simple language, they are executable programs. These executable binaries live there though you can run them from anywhere in the command line.The
.bashrc
file is found in user's home directory. On Mac it's/Users/username
. In your case, it should be/Users/regina
because your name is Regina.mongo
is the client application. It is used to interact with the mongodb database. And,mongod
is the database deamon that stores the data. So first you have to runmongod
, and then only you can connect to it using the clientmongo
and start querying.