Download MongoDB


You should place the MongoDB binaries in a central location on the file system that is easy to access and control. Consider /opt or/usr/local/bin.

In a terminal session, begin by downloading the latest release. In most cases you will want to download the 64-bit version of MongoDB.

curl > mongo.tgz

If you need to run the 32-bit version, use the following command.

curl > mongo.tgz


Replace x.y.z with the current stable version (i.e. 2.0.6).

You may also choose to install a development release, in which case you will need to specify that version number above.

Once you’ve downloaded the release, issue the following command to extract the files from the archive:

tar -zxvf mongo.tgz


You may use the following command to copy the extracted folder into a more generic location.

cp -R -n  mongodb-osx-20??-??-??/ mongodb

You can find the mongod binary, and the binaries all of the associated MongoDB utilities, in the bin/ directory within the extracted directory.

Using MongoDB

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. To create this directory, use the following command:

mkdir -p /data/db


Ensure that the system account that will run the mongod process has read and write permissions to this directory. If mongod runs under themongo user account, issue the following command to change the owner of this folder:

chown mongo /data/db

If you use an alternate location for your data directory, ensure that this user can write to your chosen data path.

You can specify, and create, an alternate path using the –dbpath option to mongod and the above command.

The 10gen builds of MongoDB contain no control scripts or method to control the mongod process. You may wish to create control scripts, modify your path, and/or create symbolic links to the MongoDB programs in your /usr/local/bin or /usr/bin directory for easier use.

For testing purposes, you can start a mongod directly in the terminal without creating a control script:

mongod --config /etc/mongod.conf


The above command assumes that the mongod binary is accessible via your system’s search path, and that you have created a default configuration file located at /etc/mongod.conf.

Among the tools included with this MongoDB distribution, is the mongo shell. You can use this shell to connect to your MongoDB instance by issuing the following command at the system prompt:



The ./bin/mongo command assumes that the mongo binary is in the bin/ sub-directory of the current directory. This is the directory into which you extracted the .tgz file.

This will connect to the database running on the localhost interface by default. At the mongo prompt, issue the following two commands to insert a record in the “test” collection of the (default) “test” database and then retrieve that record:

> { a: 1 } )
> db.test.find()