How to install MongoDB on Mac OS X




How to install MongoDB on Mac OS XIn this post we will see How to install MongoDB on Mac OS X. MongoDB is one of the most used, open-source document database, and NoSQL database. MongoDB is developed by 10gen.

STEP 1 – Downloading MongoDB .tgz file

Visit MongoDB official website and download the .tgz file from the community section of the website.
Now extract the downloded .tgz and mv the mongo directory to /usr/local/mongodb directory using following command in terminal.

$ cd ~/Download
$ tar -zxvf mongodb-osx-ssl-x86_64-3.6.1.tgz
$ sudo mv mongodb-osx-ssl-x86_64-3.6.1 /usr/local/mongodb

STEP 2 – Create MongoDB Data directory (/data/db)

MongoDB stores the data into the /data/db directory by default, so we need to create this directory and also assign proper permission using chown command.
Open the terminal run the following command

$ sudo mkdir -p /data/db
$ whoami
codebind
$ sudo chown codebind /data/db

STEP 3 – Set mongodb/bin PATH to ~/.bash_profile

Now we need to set the envirent variable for MongoDb, So the mongo and mongod command can be recognized from the terminal.
For that we need to add the mongodb/bin path to the ~/.bash_profile file.

$ cd
$ pwd
/Users/codebind
# if .bash_profile is not present follow the step 
# to create it otherwise skip the step below.
$ touch .bash_profile
$ open .bash_profile

Now .bash_profile file will open in a text editor. In this file add the following exports

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

Now restart your terminal and verify the mongodb version by following commands

$ mongo -version
MongoDB shell version: 3.6.1

STEP 4 – Start MongoDB

In order to work with mongodb we need to first run the mongod command which starts the mongo daemon .
So open two different terminals.
Now in

terminal 1

run the following command

$ mongod
MongoDB starting : pid=38042 port=27017 dbpath=/data/db/ 64-bit host=codebind.local3
//...
waiting for connections on port 27017

Now in

terminal 2

run the following command

$ mongo
MongoDB shell version: 3.6.1
connecting to: test
> show dbs
local	(empty)
admin	(empty)

Video : How to install MongoDB on Mac OS X


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





2 Comments

  1. Hello,

    I follow the instructions; however when running the mongod i got this message.

    -iMac:~ Ja$ mongod

    dyld: Symbol not found: _fchmodat

    Referenced from: /usr/local/mongodb/bin/mongod

    Expected in: /usr/lib/libSystem.B.dylib

    in /usr/local/mongodb/bin/mongod

    Trace/BPT trap: 5

Leave a Reply

Your email address will not be published.


*