Skip to content

Instantly share code, notes, and snippets.

@nrollr
Last active January 7, 2024 11:57
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • 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
@nrollr
Copy link
Author

nrollr commented Dec 26, 2015

Added HardResourceLimits and NumberOfFiles parameters to avoid the
** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000 message when entering the MongoDB Shell

@nrollr
Copy link
Author

nrollr commented Dec 26, 2015

Added --auth options to enable access control (ref. Enable Client Access Control - MongoDB manual)
This option will also remove warning messages you may have:
** WARNING: You are running this process as the root user, which is not recommended.

With access control enabled, ensure you have a user with userAdmin or userAdminAnyDatabase role in the admin database:

$ use admin
> db.createUser({ user: "Admin", pwd: "Password", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] })

Add a user with a specific role to a specific DB (eg. add the user dbRead with role read to the myDatabase -db)

$ mongo -u "Admin" -p "Password" --authenticationDatabase "admin"
> use myDatabase
> db.createUser({ user: "dbRead", pwd: "Password", roles: [ { role: "read", db: "myDatabase" } ] }) 

@taner-dll
Copy link

sudo {username} chown --> sudo chown {username}

@ncorbinII
Copy link

@animacoder +1

@rankill
Copy link

rankill commented May 10, 2016

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

and

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

@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