Posts Tagged ‘Install MongoDB on MAC OS X’

Install MongoDB On Mac OS X

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


Step 1: Download MongoDB:

Download MongoDB for MAC OS from official MongoDB site:

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
$ 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
##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"
<plist version="1.0">

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)
%d bloggers like this: