Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add mongo commands to PATH on Mac OSX

Tags:

mongodb

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.

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)

So my question is why I am not able to use mongod from any location in my terminal?

like image 843
code4jhon Avatar asked Jun 19 '14 12:06

code4jhon


People also ask

How do I run a mongo shell on a Mac?

Run the Mongo daemon, in one terminal window run ~/mongodb/bin/mongod . This will start the Mongo server. Run the Mongo shell, with the Mongo daemon running in one terminal, type ~/mongodb/bin/mongo in another terminal window. This will run the Mongo shell which is an application to access data in MongoDB.


1 Answers

Please put the PATH export into .bash_profile:

export PATH=/path/to/your/mongo/bin:$PATH

Edit: 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.

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

like image 141
Markus W Mahlberg Avatar answered Sep 18 '22 17:09

Markus W Mahlberg