Archive

Posts Tagged ‘MongoDB’

Install MongoDB On Mac OS X

Easy spets to nstall MongoDB on Mac OS X ( I have used MAC OS – Mavericks)

Image

Step 1: Download MongoDB:

Download MongoDB for MAC OS from official MongoDB site:

http://www.mongodb.org/downloads

Step 2: Install MongoDB:

$ cd ~/Download
$ tar xzf mongodb-osx-x86_64-2.6.1.tar
$ sudo mv mongodb-osx-x86_64-2.6.1 /usr/local/mongodb

 

Step 3: Create MongoDB Data Directory:

By default, MongoDB write/store data into the /data/db folder, you need to create this folder manually and assign proper permission as given below:

$ sudo mkdir -p /data/db
$ whoami
garnaik
$ sudo chown garnaik /data/db

Step 4: Set you PATH on Bash Profile for MongoDB:

Create a ~/.bash_profile file if not exists else update, and assign /usr/local/mongodb/bin to $PATH environment variable, so that you can access MongoDB on commands easily.

$ cd ~
$ pwd/Users/garnaik
$ touch .bash_profile
$ vim .bash_profile
 
exportMONGO_PATH=/usr/local/mongodb
exportPATH=$PATH:$MONGO_PATH/bin
 
##restart terminal
 
$ mongo -version
MongoDB shell version: 2.6.1

Step 5: Setting for auto start MongoDB:

To auto start yor installed mongoDB, create a launchd job on your Mac OS.

$ sudo vim /Library/LaunchDaemons/mongodb.plist

And add the following content to “/Library/LaunchDaemons/mongodb.plist”

<?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>/usr/local/mongodb/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>

Save the file and load the above job:

$ sudo launchctl load /Library/LaunchDaemons/mongodb.plist

$ ps -ef | grep mongo
    0    12     1   0  4:06PM ??         0:20.29 /usr/local/mongodb/bin/mongod
  501   542   435   0  4:37PM ttys000    0:00.00 grep mongo

Now restart your MAC OS.

Step 6: Start MongoDB:

If you already have added the above steps then MongoDB will start by the time your MAC OS started.

 

Otherwise you have to start MongoDB by using the below command:

$ mongod

Now ready to use MongoDB,

 

$ mongo
> mongod -version 
MongoDB shell version: 2.6.1
> show dbs
Local (empty)
Advertisements
%d bloggers like this: