I am Hack Sparrow
Captain of the Internets.

How to install MongoDB on Mac OS X

Installing MongoDB on Mac OS X

If you are looking for a straightforward, no-headache way to install Mongodb on Mac OS X you have come to the right place. If you are looking for a customized, tricky installation from source, you need to look somewhere else.

There are many ways to install MongoDB on MacOS X: from source, binary download, MacPorts, and Homebrew to name what I am aware about. Go the Homebrew way, and ditch the rest. In fact, use Homebrew for managing all your packages on Mac OS X. This all you need to do to get MongoDB running on your system:

$ brew update
$ brew install mongodb
$ mkdir -p /data/db

If you don't create that directory you will get an error "exception in initAndListen std::exception: dbpath (/data/db/) does not exist, terminating", when you try to start the MongoDB server.

Note to Mac OS X Lion users, if mkdir -p /data/db fails. Do this:

$ sudo mkdir -p /data/db
$ sudo chown `id -u` /data/db

What the above commands did is create the required directory and change ownership to you, so that you can run mongod without any permission errors.

If everything goes fine, you have successfully installed MongoDB on your system. To start the server, open a terminal and type:

$ mongod
MongoDB starting : pid=4932 port=27017 dbpath=/data/db/ 64-bit

To connect to the sever and playing with the data, open a terminal and type:

$ mongo
MongoDB shell version: 1.8.3

There you go! No head-ache, no dependency problems, nothing to worry about - just get the thing installed and running.

3 Responses to “How to install MongoDB on Mac OS X”

  1. Ryan says:

    Did you get your LaunchAgent to work?

    I get this error:
    > load -w ~/Library/LaunchAgents/org.mongodb.mongod.plist
    Bug: launchctl.c:2406 (25182):13: (dbfd = open(g_job_overrides_db_path, O_RDONLY | O_EXLOCK | O_CREAT, S_IRUSR | S_IWUSR)) != -1
    launch_msg(): Socket is not connected

  2. Captain says:

    I am not using LaunchAgent.

  3. Lee G says:


Make a Comment