Thursday, April 25, 2013

Installing and Running MongoDB on Mac

So, I think that mongoDB instructions are not complete enough to install it on Mac. Here is what I did to install mongoDB:

  • Download it from http://www.mongodb.org/downloads
  • Move the files to where you like it to be installed:    mv -n mongodb-osx-[platform]-[version]/ /PATH/TO/NEW/LOCATION/
  • Decompress the files: tar -zxvf mongodb.tgz
  • Make a data directory: sudo mkdir -p /PATH/TO/DATA/FOLDER/db
  • Allow mongoDB to access this directory: sudo chown `id -u` /PATH/TO/DATA/FOLDER/db
  • Create a log directory: sudo mkdir -p /PATH/TO/DATA/FOLDER/db
  • Create a config file for it in the /etc folder: sudo vi /PATH/TO/LOG/FOLDER/mongod.log
  • Fill in the configurations: 
#mongod config file
#replica setreplSet=replA
#start mongod in shardsvr modeshardsvr=true
#where to loglogpath=/PATH/TO/LOG/FOLDER/mongod.log
#log overwritten or appended tologappend=true
#fork and run in backgroundfork=true
#override portport=27018
#path to data filesdbpath=/PATH/TO/DATA/FOLDER/data/db
  • Configure: mongod --config /etc/mongod.conf
  • Run the server: /PATH/TO/MongoDB/BinFolder/mongod
  • Run the client: /PATH/TO/MongoDB/BinFolder/mongo
That's it! Of course you can add the bin folder to $PATH to make it easier for you to access and run mongoDB. Have fun creating cool databases! 

P.S. I have Mountain Lion and mongoDB 2.4.1