mongoDB tutorial install and run

Install MongoDB on OS X

Platform Support


Starting in version 2.4, MongoDB only supports OS X versions 10.6 (Snow Leopard) on Intel x86-64 and later.

MongoDB is available through the popular OS X package manager Homebrew or through the MongoDB Download site.

Install MongoDB with Homebrew

Homebrew [1] installs binary packages based on published “formulae”. The following commands will updatebrew to the latest packages and install MongoDB.

In a terminal shell, use the following sequence of commands to update“brew“ to the latest packages and install MongoDB:

brew update
brew install mongodb

Later, if you need to upgrade MongoDB, run the following sequence of commands to update the MongoDB installation on your system:

brew update
brew upgrade mongodb

Optionally, you can choose to build MongoDB from source. Use the following command to build MongoDB with SSL support:

brew install mongodb --with-openssl

You can also install the latest development release of MongoDB for testing and development with the following command:

brew install mongodb --devel
[1] Homebrew requires some initial setup and configuration. This configuration is beyond the scope of this document.

Run MongoDB

Set Up the Data Directory

Before you start mongod for the first time, you will need to create the data directory. By default, mongod writes data to the /data/db/ directory.


Create dbpath

To create the default dbpath directory, use the following command:

mkdir -p /data/db

Set dbpath Permissions

Ensure that the user that runs the mongod process has read and write permissions to this directory. For example, if you will run the mongod process, change the owner of the /data/db directory:

chown `id -u` /data/db

You must create the mongodb user separately.

You can specify an alternate path for data files using the –dbpath option to mongod. If you use an alternate location for your data directory, ensure that the alternate directory has the appropriate permissions.

Start MongoDB

To start mongod, run the executable mongod at the system prompt.

For example, if your PATH includes the location of the mongod binary, enter mongod at the system prompt.


If your PATH does not include the location of the mongod binary, enter the full path to the mongod binary.

The previous command starts a mongod instance that writes data to the /data/db/ directory. To specify an alternate data directory, start mongod with the –dbpath option:

mongod --dbpath <some alternate directory>

Whether using the default /data/db/ or an alternate directory, ensure that the user account running mongodhas read and write permissions to the directory.

Stop MongoDB

To stop the mongod instance, press Control+C in the terminal where the mongod instance is running.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s