Srini's Point of View

My thoughts on technology, food and other fancies…

How to install MongoDB on a Mac

I am starting to teach myself the MEAN stack. The MEAN stack makes use of MongoDB, Express.js, Angular.js and Node.js. The best part about this stack is that all parts of the stack can be written in Javascript. Read this wikipedia article to know more.

The best way to install mongodb is using homebrew. First make sure homebrew is upto date and there are no issues

$ brew update
$ brew doctor

Then install mongodb -

$ brew install mongodb

Once mongodb is installed, create a data directory where mongodb will create all its database files -

$ sudo mkdir -p /data/db

Now change ownership to your account so you dont have to use sudo to run mongodb-

$ sudo chown `id -u` /data/db

Thats it! Now run the ‘mongod’ command to run your instance of mongodb without using sudo.