There are numerous posts, manuals and readme articles on installation of MongoDB in Mac OS X. This post documents the steps I went through to install the latest release of MongoDB on my Mac running Mountain Lion 10.8.5 & setting it up to run as a daemon. The steps outlined below closely follow the steps shared by Github user xiaolai in his repository MongoDB-OSX-Launchctl. One of the issue I faced following the steps in his readme was the a Bad file descriptor error raised by
launchctl, possibly caused by a mistake I made in the paths of the directories required by MongDB.
To setup MongoDB to run as a daemon, download the latest version of MongoDB and decompress the dowloaded file –
Copy the contents of the folder
/opt/local/bin. Alternatively, you can use Mac Ports or Homebrew to install MongoDB. The next steps assume MongoDB binaries are present in
Before you setup MongoDB to run as a daemon, you will need to create a data directory, a directory where log files will be written and a configuration file. Follow the steps below –
1 2 3
You can provide a configuration file to MongoDB or skip the following steps. Read more about the MongoDB configuration here – http://docs.mongodb.org/manual/reference/configuration-options/. A basic MongoDB configuration file (name it
mongod.conf) looks like this –
If you have created a configuration file, copy it to the appropriate directory –
The important step in setting up MongoDB to run as a daemon in Mac OS X is to create a Plist file and use it as a
launchctl item. Create a file called
org.mongo.mongod.plist with the following contents –
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Note that the path to the
mongod and the directories created earlier should be correctly specified in the Plist file. Any errors in these program arguments result in errors.
launchctl item like so –
1 2 3 4
launchctl can be setup to run MongoDB with a Plist in
/System/Library/LaunchDaemons, however, in my case,
/Library/LaunchDaemons worked without any issues. With the release of OS X Mavericks in the horizon, I may need to update the post with any changes in the steps above.