MongoDB Fresh Install in Mac OS X

Today i need MongoDB for my project, and i forget that in my laptop don’t have MongoDB installed yet. lets get started to installing MongoDB in Mac OS X.

Download and extract
go to MongoDB Official website to download the package.
$tar xvz mongodb.xxx.xxxx.tgz
$sudo mv mongodb.xxx.xxxx /usr/local/mongodb

Add MongoDB data directory
$mkdir -p /data/db
$sudo chown user /data/db

Add MongoDB/bin $PATH
$vim ~/.bash_profile

export MONGO_PATH=/usr/local/mongodb
export PATH=$PATH:$MONGO_PATH/bin

$source ~/.bash_profile
$mongo -version
MongoDB shell version: x.x.x

Starting MongoDB
Terminal 1
$mongod
....
waiting for connections on port 27017

Terminal 2
$mongo
MongoDB shell version: x.x.x
connecting to: test
> show dbs
local 0.00GB

Create AutoStart MongoDB

$ sudo vi /Library/LaunchDaemons/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/mongodb/bin/mongod</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>KeepAlive</key>
  <true/>
  <key>WorkingDirectory</key>
  <string>/usr/local/mongodb</string>
  <key>StandardErrorPath</key>
  <string>/var/log/mongodb/error.log</string>
  <key>StandardOutPath</key>
  <string>/var/log/mongodb/output.log</string>
</dict>
</plist>

$sudo launchctl load /Library/LaunchDaemons/mongodb.plist

try to start mongodb again by type:

$mongo

Advertisements