Skip to content

Instantly share code, notes, and snippets.

@nrollr
Last active January 7, 2024 11:57
Show Gist options
  • Save nrollr/e52b9f46edf2bd8b511d to your computer and use it in GitHub Desktop.
Save nrollr/e52b9f46edf2bd8b511d to your computer and use it in GitHub Desktop.
Install MongoDB on El Capitan

Install MongoDB on El Capitan

How to install the latest stable version of MongoDB on OS X 10.11 (El Capitan).

  • Official MongoDB install documentation: Here
  • Current Stable Release: 3.0.6

Make sure you have Homebrew installed before following the different steps documented below.
Important notice: When installing Homebrew on El Capitan there is an important article you should read first: Homebrew and El Capitan

Procedure

Install MongoDB using Homebrew

Open Terminal and install MongoDB with the following command: brew install mongodb
If you require TLS/SSL support, add --with-openssl to the install command.

####Configure MongoDB Data directory By default, the mongod process uses the /data/db directory. You'll need to create this folder manually and assign proper permission. Enter the following commands:

  • sudo mkdir -p /data/db
  • sudo chown {username} /data/db
    // where {username} is the user account running the mongod process

Add the location of MongoDB binaries to $PATH

  • Add /usr/local/cellar/mongodb/3.0.6 to your PATH environment variable in .bash_profile
export MONGO_PATH=/usr/local/Cellar/mongodb/3.0.6
export PATH=$PATH:$MONGO_PATH/bin

MongoDB daemon

If you want MongoDB to run automatically after a restart, we'll need to create a Launchd daemon.

  • In Terminal enter: sudo vim /Library/LaunchDaemons/mongodb.plist
  • Add the following entries to mongodb.plist:
<?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>mongodb</string>
  <key>ProgramArguments</key>
  <array>
    <string>/usr/local/Cellar/mongodb/3.0.6/bin/mongod</string>
    <string>--auth</string>
    <string>--dbpath</string>
    <string>/Users/Username/data/db</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>KeepAlive</key>
  <true/>
  <key>WorkingDirectory</key>
  <string>/usr/local/Cellar/mongodb/3.0.6</string>
  <key>StandardErrorPath</key>
  <string>/var/log/mongodb/error.log</string>
  <key>StandardOutPath</key>
  <string>/var/log/mongodb/output.log</string>
  <key>HardResourceLimits</key>
  <dict>
    <key>NumberOfFiles</key>
    <integer>2048</integer>
  </dict>
  <key>SoftResourceLimits</key>
  <dict>
    <key>NumberOfFiles</key>
    <integer>2048</integer>
  </dict>
</dict>
</plist>
  • To finish we'll load the daemon with:
    sudo launchctl load /Library/LaunchDaemons/mongodb.plist
  • Verify with: ps -ef | grep mongo
@JuanVqz
Copy link

JuanVqz commented May 13, 2016

Please change brew install monogdb ----> brew install mongodb

and

sudo {username} chown /data/db ---> sudo chown {username}:{group} /data/db

@nrollr
Copy link
Author

nrollr commented May 29, 2016

Updated gist based on feedback,.. thnx @animacoder @rankill and @JuanVqz

@moorcroftj
Copy link

This worked great. I was using MAMP too which through various things in the mix. Remember to update the PHP ini files with the right mongodb.so (mongo.so is depracated).

@jt3k
Copy link

jt3k commented Feb 17, 2018

the link to article is wrong Homebrew and El Capitan

@jt3k
Copy link

jt3k commented Feb 17, 2018

if u want try mongo on el-captain use this app https://gcollazo.github.io/mongodbapp/ good luck

@marcosleonel
Copy link

You just saved a live, @nrollr ! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment