Sunday, 22 November 2015

Installing MongoDB on MacOS X



MongoDB Version : 3.0.7

Mac OS X Version : 10.10.4

Following are step by step installation of the mongodb on the Mac OS :

Start with the Terminal 1 :

1. Get the latest MongoDB from the downloads MongoDB

2. Go to Downloads folder  -- >  cd ~ Downloads/

3.  sudo mv mongodb-osx-x86_64-3.0.7.tgz  /Users/sachin/Documents/software/mongodb [cd ~ is /Users/sachin ]

4. cd ~ Documents/software/mongodb

5. tar xzf mongodb-osx-x86_64-3.0.7.tgz

6. By default MongoDB stores the data  in the /data/db folder , so  we require to create the data and to provide proper permission to it :

  a) sudo mkdir -p /data/db
  b) whoami
      sachin
  c) sudo chown sachin /data/db

7. Adding mongo db to $PATH  : 
  a)  cd ~
  b) pwd 
      /Users/sachin
 c)  vim .bash_profile
 d) export PATH=$PATH:/Users/sachin/Documents/software/mongodb/mongodb-osx-x86_64-3.0.7/bin

8) Starting the MongoDB :

a) Go to new Terminal 2
b) mongod    (it starts the mongo service)

9) Go to Terminal 3 :
a) mongo

MongoDB shell version: 3.0.7

connecting to: test

An Alternate to manually starting the mongoDB using the background job as following : 

10 ) Auto starting the Mongodb  using job : 

a)  sudo vim /Library/LaunchDaemons/mongodb.plist

b)  insert the following text and save the file : 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
  "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>mongodb</string>
  <key>ProgramArguments</key>
  <array>
    <string>/Users/sachin/Documents/software/mongodb/mongodb-osx-x86_64-3.0.7/bin/mongod</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>KeepAlive</key>
  <true/>
  <key>WorkingDirectory</key>
  <string>/usr/local/mongodb</string>
  <key>StandardErrorPath</key>
  <string>/var/log/mongodb/error.log</string>
  <key>StandardOutPath</key>
  <string>/var/log/mongodb/output.log</string>
</dict>
</plist>

c) Load the above mentioned job in the background :

sudo launchctl load /Library/LaunchDaemons/mongodb.plist






Welcome and Enjoy the MongoDB world !!!!!

No comments:

Post a Comment