Saturday, May 7, 2016

Installing MongoDB - OSX

Installing MongoDB is one of the most rudimentry operation(s). We can proceed in one of the 2 ways

  1. Homebrew
  2. Install from source


I prefer choice 1.

Reason, you get to install the most stable version of the application and updates can be easily handled through Homebrew.

There's a lot more to installation than downloading files. Here are a few things one has to think through

  1. Setting up mongo library. Where should this be - User directory or in a common location. Should this be /usr/local or /usr/bin or /etc...???
  2. Executable files need to be placed in right directory with shortcuts for easier access
  3. Executable files should have appropriate access privileges to ensure sanctity 
  4. Data and log files to be created in right directory with right access


Unless you are a seasoned LINUX/UNIX developer above items are a source of confusion. If you are one of the kind and like to manage things all by yourself under your nose, go right ahead with option 2. Rest all can take Option 1

Alright, now to install it from homebrew, do this

brew update
brew install mongodb

Once the installation is complete, here are a few things you need to be familiar with

  1. All mongodb executable files are available in /usr/local/bin
  2. Configuration file is available in /usr/local/etc - mongod.conf
  3. Logs and data files to be stored in /usr/local/var/log && /usr/local/var/mongodb


With this in mind our next step is to make sure we have mongodb DB service as a part of OSX launch control process

Create a soft link for config file
ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents

Then, add it to OSX launch process
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

And that's all to it. Now run your mongo Db with simple
"mongo" command. You should now be able to control all MONGO processes with launch control commands