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
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
/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
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
Please change brew install monogdb ----> brew install mongodb
and
sudo {username} chown /data/db ---> sudo chown {username} /data/db