How to install MongoDB Mac

Rafael Nunes
2 min readJun 4, 2016

--

Quick tutorial on installing MongoDB for you to start play around with this NoSQL database. But first explore their website: https://www.mongodb.com

Download MongoDB

Look forward the last version of MongoDB at Download Center and copy the link to use bellow.

Open the terminal and type the commands:

$ cd Downloads
$ curl -O https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-3.0.6.tgz

Extract downloaded archive

$ tar -zxvf mongodb-osx-x86_64–3.0.6.tgz

Move binaries to local user

$ sudo mv mongodb-osx-x86_64–3.0.6 /usr/local/mongodb

Choosing the file data storage

MongoDB uses /data/db folder to storage the data, so now you need to manually create this folder if is not already there.

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

Adding Mongo to Environment Variables

First certify you are in the user directory.

$ cd ~
$ pwd
/Users/myusername

Then create the bash_profile file.

$ touch .bash_profile
$ vim .bash_profile

Now you are in the vim shell mode. By default it should be in the — INSERT — mode on, if not just type “i”.

Now write the commands below:

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

Press esc to exit the INSERT MODE, then you should enter :wq which means write and quite vim mode. After this you just have updated the PATH, restart your Terminal and type:

$ mongo -version
MongoDB shell version: X.X.X

If you did it correctly then you should have now the version of the MongoDB installed as the output.

Trying to access the DB

Open two terminals windows.

In the first you will open the server which will listen the requisitions (normally at port 27017):

$ mongod

On the other terminal type the next command that will open the Mongo Shell version and you can play around it now.

$ mongo

For example, you can take a look over your databases.

> show dbs

Now that you have it correctly set up you can invest your time to explore this awesome Open Source platform.

Enjoy =)

--

--

Rafael Nunes
Rafael Nunes

Written by Rafael Nunes

Software Engineer @ Airtasker | casual blog post writer & open sourcerer https://peaonunes.com

Responses (3)