Installing MongoDB on OS X

Dave Everitt, last updated (none)

The 'quickstart' for OS X on the MongoDB site could be clearer. Here's a condensed version with more info…

Copy the download URL on the MongoDB site (don't click) for the latest download for your system:

Open Terminal and go to where you keep source files (good to create a directory if you don't have it already with mkdir src) e.g.:
cd ~/src

Use curl with the URL you've copied, plus > (between spaces) and the filename you'll save it as e.g. (for the 64-bit version of Mongo 1.8.1):

curl > mongo.tgz

Make the default directory for MongoDB to store it's data - enter:
mkdir -p /data/db

(-p also creates the intermediate directory data)

If you want see what's there after you've used MongoDB, type:
cd /data/db;ls -al

Add a couple of aliases to your .bash_profile, .bashrc, .bash_login file (or wherever you keep your custom bash stuff) e.g. for the above version of MongoDB downloaded to ~/src:

alias mongod="/Users/yourusername/src/mongodb-osx-x86_64-1.8.1/bin/mongod"
alias mongo="/Users/yourusername/src/mongodb-osx-x86_64-1.8.1/bin/mongo"

To use these new aliases, close the Terminal window and open a new one. You can now start the MongoDB server with:

then open another Terminal window and launch the MongoDB shell by typing:

In the MongoDB shell that's now started up, create and retrieve a test document e.g. 'foo':

> { a : 1 } )

You'll see the result. Now you can start using MongoDB.

References and further information


MongoDB, OS X, bash, Terminal, Leopard, Snow Leopard