Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
How to install MongoDB 2.0 on Mac OS X (>= Leopard)

How to install MongoDB 2.0 on Mac OS X (>= Leopard)

Procedure

The whole install procedure is like the following.
You would have to do 7 steps.

  1. Download the latest tar file, and expand it.
  2. Move it to /usr/local/, and make a symbolic link to the folder.
  3. Add path to MongoDB binaries.
  4. Make an user that "mongod" runs on, and group that owns the user.
  5. Make a database directory.
  6. Make a log file.
  7. Install LaunchDaemon file.

Here are the details...

Keep it on mind that # means operating as the root, % means operating as an user.

Step 1

Download the latest tar file from http://www.mongodb.org/downloads , and expand it. Then you could see a folder like this: "mongodb-osx-x86_64-2.0.0". MongoDB is really simple, so that are the all the files that are needed to start up MongoDB.

Step 2

Move it to "/usr/local".

 # mv mongodb-osx-x86_64-2.0.0 /usr/local/

Then make a symbolic link to the folder as the name of shorter one so that you could access the folder easily.

 # ln -s /usr/local/mongodb-osx-x86_64-2.0.0 /usr/local/mongodb

Step 3

Add the file that points to the binaries into "/etc/paths.d" directory, then you can access the binaries directly on your console like this: "% mongo".

 # echo '/usr/local/mongodb/bin' > /etc/paths.d/mongodb

Step 4

Make an account that "mongod" uses. First of all, find an UniqueID that is not currently in use, using the following command.

 # dscl . list /Users UniqueID

Then, pick up one that is less than 500 not to be listed on the login window, and follow the commands below.

 # dscl . -create /Users/_mongo
 # dscl . -create /Users/_mongo PrimaryGroupID 0
 # dscl . -create /Users/_mongo UniqueID 250

You should change the UniqueID number depending on your environment.

 # dscl . -append /Users/_mongo RecordName "mongo"
 # dscl . -create /Users/_mongo UserShell /usr/bin/false

 # dscl . -create /Groups/_mongo
 # dscl . -create /Groups/_mongo PrimaryGroupID 250

If the same PrimaryGroupID as the user is already in use, change it.

 # dscl . -append /Groups/_mongo RecordName mongo
 # dscl . -append /Groups/_mongo GroupMembership _mongo

Step 5

Let's make a database directory.

 # mkdir /var/db/mongodb
 # chown mongo:mongo /var/db/mongodb

Step 6

Then make a log file.

 # touch /var/log/mongodb.log
 # chown mongo:mongo /var/log/mongodb.log

Step 7

Download LaunchDaemon file from this gist (org.mongodb.mongod.plist). If you have correctly followed the procedure above, you don't have to correct anything in the file.

Move it to /Library/LaunchDaemons/ , and have Mac load it.

 # mv org.mongodb.mongod.plist /Library/LaunchDaemons/
 # launchctl load /Library/LaunchDaemons/org.mongodb.mongod.plist

That's all! Now you must be able to access MongoDB! Type "mongo" on your console!

 % mongo

Enjoy it!

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.mongodb.mongod</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/mongodb/bin/mongod</string>
<string>--dbpath</string>
<string>/var/db/mongodb</string>
<string>--logpath</string>
<string>/var/log/mongodb.log</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>OnDemand</key>
<false/>
<key>UserName</key>
<string>_mongo</string>
</dict>
</plist>
@ojingo

Does this still work? I just tried it and came up empty...do you have to chown the plist file as well to root?

@troyth

Yes, it seems you have to change the ownership of the plist before calling the launchctl command:

sudo chown root /Library/LaunchDaemons/org.mongodb.mongod.plist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.