MongoDB Installation on OS X

The instructions were modified from http://hunterford.me/mongodb-startup-item/. This procedure should work fine on OS X 10.10 Yosemite, 10.11. El Capitan and OS X 10.12 Sierra, but also older versions.

Download and install the binary

cd ~/Downloads/
mkdir mongodb
curl -O https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-3.4.4.tgz
tar -zxvf mongodb-osx-x86_64-3.4.4.tgz -C ./mongodb --strip-components 1
sudo mkdir -p /usr/local/bin
sudo cp mongodb/bin/* /usr/local/bin/
sudo touch /var/log/mongodb.log
sudo mkdir -p /data/db/mongodb
sudo chmod g+w /data/db/mongodb
sudo chmod o+w /data/db/mongodb

The databases have to go somewhere; one example with system-wide availability would be /data/db/mongodb/. The same path has to be used in the configuration below (--dbpath).

sudo mkdir -p /data/db/mongodb/

Create a launch item

The last point is just to use a standard place for the DB files. This has to be reflected in the launch file, which in this case is saved as /Library/LaunchDaemons/org.mongo.mongod.plist. One has to write this as root, e.g. using
sudo nano /Library/LaunchDaemons/org.mongo.mongod.plist

... and paste the following content; then CTRL-O

<?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.mongo.mongod</string>
      <key>RunAtLoad</key>
         <true/>
      <key>ProgramArguments</key>
         <array>
            <string>/usr/local/bin/mongod</string>
            <string>--dbpath</string>
            <string>/data/db/mongodb/</string>
            <string>--logpath</string>
            <string>/var/log/mongodb.log</string>
            <string>--bind_ip</string>
            <string>127.0.0.1</string>
         </array>
   </dict>
</plist>

Now the launch file has to be activated; it will start mongos and keep it alive.
sudo chown root:wheel /Library/LaunchDaemons/org.mongo.mongod.plist
sudo launchctl load /Library/LaunchDaemons/org.mongo.mongod.plist
sudo launchctl start org.mongo.mongo

And you should be all set. Obviously, now you have to create the databases & collections ...
Topic revision: r6 - 07 Jun 2017, MichaelBaudis
Michael Baudis