Installing MongoDB on OS X

Dave Everitt, last updated 04-Aug-2013

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:
www.mongodb.org/downloads

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 http://fastdl.mongodb.org/osx/mongodb-osx-x86_64-1.8.1.tgz > 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:
mongod

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

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

> db.foo.save( { a : 1 } )
> db.foo.find()

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

References and further information

www.mongodb.org/display/DOCS/Quickstart+OS+X

linguisticlogic.wordpress.com/2010/09/18/bashing-up-mongodb-on-mac-os-x-10-6/

Tags

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

Comments:

From: Hengki, Tue Feb 7 15:15 2012
Hi That is very useful, I was using a previous version of Spring Data for mongodb and struggled migrating to the new one.

From: Nacho, Sun Feb 12 00:11 2012
There are soanttiius where installing the software is simply denied/unfavorable, normally happens in case of CI (Continuous integration) testing with Bamboo or Hudson. Where the machine running the server has no MongoDB installed. It is likely that all the persistence and even business tests fail badly. I am not able to find the solution until now, however, do you have any idea to unit test the application in such circumstances. Thanks for sharing your experiences in advance!

From: Dave Everitt, Sun Feb 24 00:11 2012
@Nacho I'm afraid in that case, I can only suggest using a local setup for your testing.

From: Amarsingh, Sat Feb 25 13:01 2012
I ran into a slimiar issue using the Java driver connecting to a server (mongod.exe). Make sure you use the -rest flag. That seemed to work for me.

From: Briptu, Wed Feb 29 16:15 2012
Nicely stated. If you use a much less structured DB, you create structure at the app layer. In the end, you just have to decide what you care to build and what you don't. In the case of Mongo, I've enjoyed it thus far and hope to find some scaling points in the not so distant future.

From: Dvious, Sun Nov 11 11:58 2012
Give yourself a pat on the back! I have spent three days searching, including the 10gen site - yours are the only OS X instructions that worked for me.
My ongoing thanks.

From: Dave Everitt, Sun Nov 11 11:58 2012
@Dvious glad it helped! After going through any process where the 'official' guide fails, I always try to write up the results for others.

Add a comment…

Comments (2000 characters/300 word limit) appear after approval. Add your email if you'd like a reply (it can be entered safely and won't be published, stored or spammed).

Name:
Email (optional):
Comment: