How to Install MongoDB on a Mac
In this guide we're going to walk through how to install and configure Mongo on your system.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

Now if you do not have homebrew installed and your on a Mac then go to brew.sh and then copy this line of code right here

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

and then open up your terminal and paste it in. So here is the terminal. So if you do not have a brew already installed then you can run it right here and it will go through, it might take a few minutes but it will install and then once you have that you'll be ready to install Mongo. The first command to run will be brew update. Now I've already run brew update on my system and if you've recently done it then you don't have to either. Brew update will just make sure that you have the latest version of homebrew if you already had it installed. After that run brew install mongodb. If you run that then homebrew will go out and find all the dependencies and build the entire system for you and you will be up and running with it. I already have Mongo on my system so I do not need to run the command but it's a pretty basic command to run. You don't have to be an sudo or anything like that for this specific command. Now after that has run then go and create a data directory. To do this you're going to type in mkdir -p /data/db.

This is the directory that Mongo needs because that's where it's going to store all of the data and it's going to store it right inside of this directory. So I already have this on my system and the way I can know that is if I type ls and then run it. You can see that I have each one of the collections right here. If you are new to Mongo and you don't have it installed on your system then you need to create that directory. Now another thing that you will have to do is you're going to have to update the permissions on this directory so type in

sudo chown -R `id -un`  /data/db 

What that's going to do is it's going to update the permissions for that directory so that you can run all of the various commands and we can actually get going with Mongo. So once you type that you'll have to enter your password in and then you will be good to go. Now I've already run that so I don't need to run that specific command. Once you've gone through all of that the way that you can test to make sure that your system is working is to startup the Mongo. It's called the Mongo demon and so you can type in mongod just like that and if you hit return it should start everything up. Now you can open up in a new terminal by typing command t and now if I just type mongo it's going to open up a mongo shell for me right here and I can get up and running. So if you follow all those commands you'll be able to get Mongo on your system and you can start with the rest of the course.

Resources